2010-08-13 15:36:38 +00:00
|
|
|
/* GStreamer video re-encoder element
|
|
|
|
* Copyright (C) <2010> Edward Hervey <bilboed@bilboed.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 23:05:09 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2010-08-13 15:36:38 +00:00
|
|
|
*/
|
|
|
|
#ifndef __SMART_ENCODER_H__
|
|
|
|
#define __SMART_ENCODER_H__
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
2020-03-12 06:55:52 +00:00
|
|
|
#define GST_TYPE_SMART_ENCODER (gst_smart_encoder_get_type())
|
2020-07-04 16:33:20 +00:00
|
|
|
G_DECLARE_FINAL_TYPE (GstSmartEncoder, gst_smart_encoder, GST, SMART_ENCODER, GstBin)
|
2010-08-13 15:36:38 +00:00
|
|
|
|
|
|
|
struct _GstSmartEncoder {
|
2020-07-04 16:33:20 +00:00
|
|
|
GstBin parent;
|
2010-08-13 15:36:38 +00:00
|
|
|
|
|
|
|
GstPad *sinkpad, *srcpad;
|
|
|
|
|
2020-07-04 16:33:20 +00:00
|
|
|
gboolean pushed_segment;
|
|
|
|
|
|
|
|
/* Segment received upstream */
|
|
|
|
GstSegment input_segment;
|
|
|
|
|
|
|
|
/* The segment we pushed downstream */
|
|
|
|
GstSegment output_segment;
|
|
|
|
|
|
|
|
/* Internal segments to compute buffers running time before pushing
|
|
|
|
* them downstream. It is the encoder segment when reecoding gops,
|
|
|
|
* and the input segment when pushing them unmodified. */
|
|
|
|
GstSegment internal_segment;
|
|
|
|
GstClockTime last_dts;
|
|
|
|
|
smartencoder: clean up and extend accepted formats
* Add support for H265
* Don't overwrite original codec_data / streamheader in the output
caps, but instead allow them to change and send them to the
combiner at the right moment: encoder caps, reencoded GOP,
original caps, original GOP(s), and potentially encoder caps
and rencoded last GOP.
* For H264 / H265, force usage of a format with inband SPS / PPS
(avc3 / hev1), this is cleaner than misadvertising avc1, hvc1 and
some muxers like mp4mux will actually advertise both differently.
Unfortunately, while mp4 supports updating the codec_data and using
avc1 with no in-band SPS / PPS updates, it turns out some decoders
(eg chrome / firefox) don't handle this particularly well and stop
decoding after the reencoded GOP. We could expose a switch to
force usage of avc1 / hvc1 nevertheless, but for now stick to
requiring that the parser output SPS / PPS in-band with
config-interval=-1 (that has not changed)
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1249>
2021-08-10 00:09:09 +00:00
|
|
|
GstCaps *original_caps;
|
|
|
|
gboolean push_original_caps;
|
2020-07-04 16:33:20 +00:00
|
|
|
GstEvent *segment_event;
|
|
|
|
GstEvent *stream_start_event;
|
2010-08-13 15:36:38 +00:00
|
|
|
|
|
|
|
/* Pending GOP to be checked */
|
2020-07-04 16:33:20 +00:00
|
|
|
GList* pending_gop;
|
|
|
|
guint64 gop_start; /* GOP start PTS in the `input_segment` scale. */
|
|
|
|
guint64 gop_stop; /* GOP end PTS in the `input_segment` scale. */
|
2010-08-13 15:36:38 +00:00
|
|
|
|
|
|
|
/* Internal recoding elements */
|
|
|
|
GstPad *internal_sinkpad;
|
|
|
|
GstPad *internal_srcpad;
|
|
|
|
GstElement *decoder;
|
|
|
|
GstElement *encoder;
|
|
|
|
|
2020-07-04 16:33:20 +00:00
|
|
|
GstFlowReturn internal_flow;
|
|
|
|
GMutex internal_flow_lock;
|
|
|
|
GCond internal_flow_cond;
|
2010-08-13 15:36:38 +00:00
|
|
|
};
|
|
|
|
|
2020-07-04 16:33:20 +00:00
|
|
|
gboolean gst_smart_encoder_set_encoder (GstSmartEncoder *self,
|
|
|
|
GstCaps *format,
|
|
|
|
GstElement *encoder);
|
|
|
|
|
2010-08-13 15:36:38 +00:00
|
|
|
G_END_DECLS
|
|
|
|
|
|
|
|
#endif /* __SMART_ENCODER_H__ */
|