-
Notifications
You must be signed in to change notification settings - Fork 0
/
gstshvideoenc.c
3649 lines (3375 loc) · 105 KB
/
gstshvideoenc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* \page enc gst-sh-mobile-enc
* gst-sh-mobile-enc - Encodes raw YUV image data to MPEG4/H264 video stream on
* SuperH environment using libshcodecs HW codec.
*
* \section dec-description Description
* This element is designed to use the HW video processing modules of the Renesas
* SuperH chipset to encode mpeg4/h264 video streams. This element is not usable
* in any other environments and it requires libshcodes HW codec to be installed.
*
* The encoding settings are given as properties to the encoder or using a control
* file. Examples of control files can be found from /cntl_file -folder.
*
* \section enc-examples Example launch lines
* \subsection enc-examples-1 Encoding from a file to a file
* \code
* gst-launch filesrc location=test.yuv ! gst-sh-mobile-enc stream-type=mpeg4
* width=320 height=240 framerate=300 ! filesink location=test.m4v
* \endcode
* This is a very simple pipeline where filesrc and filesink elements are used
* to read the raw data and write the encoded data. In this pipeline the
* gst-sh-mobile-enc operates in pull mode, so it is the element which drives the
* data flow.
*
* \subsection enc-examples-2 Encoding from a webcam to a file
* \code
* gst-launch v4l2src device=/dev/video0 ! image/jpeg, width=320, height=240,
* framerate=15/1 ! jpegdec ! ffmpegcolorspace ! gst-sh-mobile-enc
* stream-type=mpeg4 bitrate=250000 ! filesink location=test.m4v
* \endcode
*
* \image html encoder_example.jpeg
*
* In this example, webcam is used as the streaming source via v4l2src element.
* the webcam in this example provides jpeg image data. This pipeline works in
* push mode, so we need to specify the stream properties using static caps after
* the v4l2src element. jpegdec decodes the jpeg images and ffmpegcolorspace is
* used to convert the image data for the encoder. Again, filesink is used to
* write the encoded video stream into a file.
*
* \subsection enc-examples-3 Encoding from a webcam to network
* \code
* gst-launch v4l2src device=/dev/video0 ! image/jpeg, width=320, height=240,
* framerate=15/1 ! jpegdec ! ffmpegcolorspace ! gst-sh-mobile-enc
* ! rtpmp4vpay ! udpsink host=192.168.10.10 port=5000 sync=false
* \endcode
* This line is similar to the one above. At this time, the video is not stored
* in a file but sent over the network using udpsink -element. Before sending,
* the video is packed into RTP frame using rtpmp4vpay -element.
*
* The following line allows playback of the video in PC:
* \code
* gst-launch udpsrc port=5000 caps="application/x-rtp, clock-rate=90000"
* ! gstrtpjitterbuffer latency=0 ! rtpmp4vdepay ! video/mpeg, width=320,
* height=240, framerate=15/1 ! ffdec_mpeg4 ! ffmpegcolorspace ! ximagesink
* \endcode
*
* \section enc-properties Properties
* \copydoc gst_sh_video_enc_properties
*
* \section enc-pads Pads
* \copydoc enc_sink_factory
* \copydoc enc_src_factory
*
* \section enc-license License
* 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 Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
*
* Johannes Lahti <[email protected]>
* Pablo Virolainen <[email protected]>
* Aki Honkasuo <[email protected]>
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <poll.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <string.h>
#include <pthread.h>
#include <gst/gst.h>
#include "gstshvideoenc.h"
#include "gstshencdefaults.h"
#include "cntlfile/ControlFileUtil.h"
/**
* \var enc_sink_factory
* Name: sink \n
* Direction: sink \n
* Available: always \n
* Caps:
* - video/x-raw-yuv, format=(fourcc)NV12, width=(int)[48, 720],
* height=(int)[48, 576], framerate=(fraction)[1, 25]
* - video/x-raw-yuv, format=(fourcc)NV12, width=(int)[48, 720],
* height=(int)[48, 480], framerate=(fraction)[1, 30]
*/
static GstStaticPadTemplate enc_sink_factory =
GST_STATIC_PAD_TEMPLATE("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS(
"video/x-raw-yuv, "
"format = (fourcc) NV12,"
"width = (int) [48, 720],"
"height = (int) [48, 480],"
"framerate = (fraction) [0, 30]"
";"
"video/x-raw-yuv, "
"format = (fourcc) NV12,"
"width = (int) [48, 720],"
"height = (int) [48, 576],"
"framerate = (fraction) [0, 25]"
)
);
/**
* \var enc_src_factory
* Name: src \n
* Direction: src \n
* Available: always \n
* Caps:
* - video/mpeg, width=(int)[48, 720], height=(int)[48, 576],
* framerate=(fraction)[1, 25], mpegversion=(int)4
* - video/mpeg, width=(int)[48, 720], height=(int)[48, 480],
* framerate=(fraction)[1, 30], mpegversion=(int)4
* - video/x-h264, width=(int)[48, 720], height=(int)[48, 576],
* framerate=(fraction)[1, 25], h264version=(int)h264
* - video/x-h264, width=(int)[48, 720], height=(int)[48, 480],
* framerate=(fraction)[1, 30], h264version=(int)h264
*/
static GstStaticPadTemplate enc_src_factory =
GST_STATIC_PAD_TEMPLATE("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS(
"video/mpeg,"
"width = (int) [48, 720],"
"height = (int) [48, 576],"
"framerate = (fraction) [0, 25],"
"mpegversion = (int) 4"
";"
"video/mpeg,"
"width = (int) [48, 720],"
"height = (int) [48, 480],"
"framerate = (fraction) [0, 30],"
"mpegversion = (int) 4"
"; "
"video/x-h264,"
"width = (int) [48, 720],"
"height = (int) [48, 576],"
"framerate = (fraction) [0, 25],"
"variant = (string) itu,"
"h264version = (string) h264"
"; "
"video/x-h264,"
"width = (int) [48, 720],"
"height = (int) [48, 480],"
"framerate = (fraction) [0, 30],"
"variant = (string) itu,"
"h264version = (string) h264"
)
);
GST_DEBUG_CATEGORY_STATIC(gst_sh_mobile_debug);
#define GST_CAT_DEFAULT gst_sh_mobile_debug
static GstElementClass *parent_class = NULL;
/**
* \enum gst_sh_video_enc_properties
* Here is the list of the most important properties of gst-sh-mobile-enc.
* There are a lot of other available properties, see the source code for more
* information.
* - "cntl-file" (string). Name of the control file containing encoding
* parameters. Default: NULL
* - "stream-type" (string). The type of the video stream ("h264"/"mpeg4").
* Default: None (An error message will display if the property is not set
* or can not be determined from the stream).
* - "width" (long). The width of the video stream (48-720px). Default: 0
* (An error message will display if the property is not set or can not
* be determined from the stream).
* - "height" (long). The width of the video stream (48-576px). Default: 0
* (An error message will display if the property is not set or can not
* be determined from the stream).
* - "framerate" (long). The framerate of the video stream multiplied by 10 (0-300).
* Default: 0 (An error message will display if the property is not set or
* can not be determined from the stream).
* - "bitrate" (long). The bitrate of the video stream (0-10000000).
* Default: 384000 for mpeg4 and 2000000 for h264
* - "i-vop-interval" (long). Interval of intra-coded video object planes.
* Default: 30
* - "noise-reduction" (long). For motion-compensated macroblocks, a difference
* equal to or smaller than this setting is treated as 0 for encoding (0-4).
* Default: 0.
* - "weighted-q-mode" (long). Used to specify whether weighted quantization for
* encoding is used or not (0/1). Default: 0.
*/
enum gst_sh_video_enc_properties
{
PROP_0,
PROP_CNTL_FILE,
/* COMMON */
PROP_STREAM_TYPE,
PROP_WIDTH,
PROP_HEIGHT,
PROP_FRAMERATE,
PROP_BITRATE,
PROP_I_VOP_INTERVAL,
PROP_MV_MODE,
PROP_FCODE_FORWARD,
PROP_SEARCH_MODE,
PROP_SEARCH_TIME_FIXED,
PROP_RATECONTROL_SKIP_ENABLE,
PROP_RATECONTROL_USE_PREVQUANT,
PROP_RATECONTROL_RESPECT_TYPE,
PROP_RATECONTROL_INTRA_THR_CHANGEABLE,
PROP_CONTROL_BITRATE_LENGTH,
PROP_INTRA_MACROBLOCK_REFRESH_CYCLE,
PROP_VIDEO_FORMAT,
PROP_FRAME_NUM_RESOLUTION,
PROP_NOISE_REDUCTION,
PROP_REACTION_PARAM_COEFF,
PROP_WEIGHTED_Q_MODE,
PROP_I_VOP_QUANT_INITIAL_VALUE,
PROP_P_VOP_QUANT_INITIAL_VALUE,
PROP_USE_D_QUANT,
PROP_CLIP_D_QUANT_FRAME,
PROP_QUANT_MIN,
PROP_QUANT_MIN_I_VOP_UNDER_RANGE,
PROP_QUANT_MAX,
PROP_PARAM_CHANGEABLE,
PROP_CHANGEABLE_MAX_BITRATE,
/* MPEG4 */
PROP_OUT_VOS,
PROP_OUT_GOV,
PROP_ASPECT_RATIO_INFO_TYPE,
PROP_ASPECT_RATIO_INFO_VALUE,
PROP_VOS_PROFILE_LEVEL_TYPE,
PROP_VOS_PROFILE_LEVEL_VALUE,
PROP_OUT_VISUAL_OBJECT_IDENTIFIER,
PROP_VISUAL_OBJECT_VERID,
PROP_VISUAL_OBJECT_PRIORITY,
PROP_VIDEO_OBJECT_TYPE_INDICATION,
PROP_OUT_OBJECT_LAYER_IDENTIFIER,
PROP_VIDEO_OBJECT_LAYER_VERID,
PROP_VIDEO_OBJECT_LAYER_PRIORITY,
PROP_ERROR_RESILIENCE_MODE,
PROP_VIDEO_PACKET_SIZE_MB,
PROP_VIDEO_PACKET_SIZE_BIT,
PROP_VIDEO_PACKET_HEADER_EXTENTION,
PROP_DATA_PARTITIONED,
PROP_REVERSIBLE_VLC,
PROP_HIGH_QUALITY,
PROP_RATECONTROL_VBV_SKIPCHECK_ENABLE,
PROP_RATECONTROL_VBV_I_VOP_NOSKIP,
PROP_RATECONTROL_VBV_REMAIN_ZERO_SKIP_ENABLE,
PROP_RATECONTROL_VBV_BUFFER_UNIT_SIZE,
PROP_RATECONTROL_VBV_BUFFER_MODE,
PROP_RATECONTROL_VBV_MAX_SIZE,
PROP_RATECONTROL_VBV_OFFSET,
PROP_RATECONTROL_VBV_OFFSET_RATE,
PROP_QUANT_TYPE,
PROP_USE_AC_PREDICTION,
PROP_VOP_MIN_MODE,
PROP_VOP_MIN_SIZE,
PROP_INTRA_THR,
PROP_B_VOP_NUM,
/* H264 */
PROP_REF_FRAME_NUM,
PROP_OUTPUT_FILLER_ENABLE,
PROP_CLIP_D_QUANT_NEXT_MB,
PROP_RATECONTROL_CPB_SKIPCHECK_ENABLE,
PROP_RATECONTROL_CPB_I_VOP_NOSKIP,
PROP_RATECONTROL_CPB_REMAIN_ZERO_SKIP_ENABLE,
PROP_RATECONTROL_CPB_BUFFER_UNIT_SIZE,
PROP_RATECONTROL_CPB_BUFFER_MODE,
PROP_RATECONTROL_CPB_MAX_SIZE,
PROP_RATECONTROL_CPB_OFFSET,
PROP_RATECONTROL_CPB_OFFSET_RATE,
PROP_INTRA_THR_1,
PROP_INTRA_THR_2,
PROP_SAD_INTRA_BIAS,
PROP_REGULARLY_INSERTED_I_TYPE,
PROP_CALL_UNIT,
PROP_USE_SLICE,
PROP_SLICE_SIZE_MB,
PROP_SLICE_SIZE_BIT,
PROP_SLICE_TYPE_VALUE_PATTERN,
PROP_USE_MB_PARTITION,
PROP_MB_PARTITION_VECTOR_THR,
PROP_DEBLOCKING_MODE,
PROP_USE_DEBLOCKING_FILTER_CONTROL,
PROP_DEBLOCKING_ALPHA_OFFSET,
PROP_DEBLOCKING_BETA_OFFSET,
PROP_ME_SKIP_MODE,
PROP_PUT_START_CODE,
PROP_SEQ_PARAM_SET_ID,
PROP_PROFILE,
PROP_CONSTRAINT_SET_FLAG,
PROP_LEVEL_TYPE,
PROP_LEVEL_VALUE,
PROP_OUT_VUI_PARAMETERS,
PROP_CHROMA_QP_INDEX_OFFSET,
PROP_CONSTRAINED_INTRA_PRED,
PROP_LAST
};
#define STREAM_TYPE_H264 "h264"
#define STREAM_TYPE_MPEG4 "mpeg4"
#define STREAM_TYPE_NONE ""
/**
* Initializes shvideoenc class
* @param g_class Gclass
* @param data user data pointer, unused in the function
*/
static void gst_sh_video_enc_init_class(gpointer g_class, gpointer data);
/**
* Initializes SH hardware video encoder
* @param klass Gstreamer element class
*/
static void gst_sh_video_enc_base_init(gpointer klass);
/**
* Disposes the encoder
* @param object Gstreamer element class
*/
static void gst_sh_video_enc_dispose(GObject * object);
/**
* Initializes the class for encoder
* @param klass Gstreamer SH video encoder class
*/
static void gst_sh_video_enc_class_init(GstSHVideoEncClass *klass);
/**
* Initializes the encoder
* @param shvideoenc Gstreamer SH video element
* @param gklass Gstreamer SH video encode class
*/
static void gst_sh_video_enc_init(GstSHVideoEnc *shvideoenc,
GstSHVideoEncClass *gklass);
/**
* Event handler for encoder sink events
* @param pad Gstreamer sink pad
* @param event The Gstreamer event
* @return returns true if the event can be handled, else false
*/
static gboolean gst_sh_video_enc_sink_event(GstPad * pad, GstEvent * event);
/**
* Initializes the encoder sink pad
* @param pad Gstreamer sink pad
* @param caps The capabilities of the data to encode
* @return returns true if the video capatilies are supported and the video can
* be decoded, else false
*/
static gboolean gst_sh_video_enc_set_caps(GstPad * pad, GstCaps * caps);
/**
* Handles the activation event. Activates the element in pull mode, if it
* is supported.
* @param pad Gstreamer sink pad
* @return returns true if the event is handled without errors, else false
*/
static gboolean gst_sh_video_enc_activate(GstPad *pad);
/**
* Function to start the pad task
* @param pad Gstreamer sink pad
* @param active true if the task needs to be started or false to stop the task
* @return returns true if the event is handled without errors, else false
*/
static gboolean gst_sh_video_enc_activate_pull(GstPad *pad, gboolean active);
/**
* The encoder function and launches the thread if needed
* @param pad Gstreamer sink pad
* @param buffer The raw data for encoding.
* @return returns GST_FLOW_OK if the function runs without errors
*/
static GstFlowReturn gst_sh_video_enc_chain(GstPad *pad, GstBuffer *buffer);
/**
* The encoder sink pad task
* @param enc Gstreamer SH video encoder
*/
static void gst_sh_video_enc_loop(GstSHVideoEnc *enc);
/**
* The function will set the encoder properties
* @param object The object where to get Gstreamer SH video Encoder object
* @param prop_id The property id
* @param value The value of the property
* @param pspec not used in the function
*/
static void gst_sh_video_enc_set_property(GObject *object, guint prop_id,
const GValue *value,
GParamSpec * pspec);
/**
* The function will return the values of the encoder properties
* @param object The object where to get Gstreamer SH video Encoder object
* @param prop_id The property id
* @param value The value of the property
* @param pspec not used in the function
*/
static void gst_sh_video_enc_get_property(GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
/**
* The encoder sink event handler and calls sink pad push event
* @param pad Gstreamer sink pad
* @param event Event information
* @return Returns the value of gst_pad_push_event()
*/
static gboolean gst_sh_video_enc_sink_event(GstPad * pad, GstEvent * event);
/**
* Gstreamer source pad query
* @param pad Gstreamer source pad
* @param query Gsteamer query
* @return Returns the value of gst_pad_query_default
*/
static gboolean gst_sh_video_enc_src_query(GstPad * pad, GstQuery * query);
/**
* Callback function for the encoder input
* @param encoder shcodecs encoder
* @param user_data Gstreamer SH encoder object
* @return 0 if encoder should continue. 1 if encoder should pause.
*/
static int gst_sh_video_enc_get_input(SHCodecs_Encoder * encoder, void *user_data);
/**
* Callback function for the encoder output
* @param encoder shcodecs encoder
* @param data the encoded video frame
* @param length size the encoded video frame buffer
* @param user_data Gstreamer SH encoder object
* @return 0 if encoder should continue. 1 if encoder should pause.
*/
static int gst_sh_video_enc_write_output(SHCodecs_Encoder * encoder,
unsigned char *data, int length,
void *user_data);
/**
* GStreamer state handling. We need this for pausing the encoder.
* @param element GStreamer element
* @param transition Flag indicating which transition to handle
* @return GST_STATE_CHANGE_SUCCESS if everything is ok. Otherwise
* GST_STATE_CHANGE_FAILURE
*/
static GstStateChangeReturn
gst_sh_video_enc_change_state(GstElement *element, GstStateChange transition);
static void
gst_sh_video_enc_init_class(gpointer g_class, gpointer data)
{
parent_class = g_type_class_peek_parent(g_class);
gst_sh_video_enc_class_init((GstSHVideoEncClass *)g_class);
}
GType gst_sh_video_enc_get_type(void)
{
static GType object_type = 0;
if (object_type == 0)
{
static const GTypeInfo object_info =
{
sizeof(GstSHVideoEncClass),
gst_sh_video_enc_base_init,
NULL,
gst_sh_video_enc_init_class,
NULL,
NULL,
sizeof(GstSHVideoEnc),
0,
(GInstanceInitFunc)gst_sh_video_enc_init
};
object_type =
g_type_register_static(GST_TYPE_ELEMENT,
"gst-sh-mobile-enc",
&object_info, (GTypeFlags)0);
}
return object_type;
}
static void
gst_sh_video_enc_base_init(gpointer klass)
{
static const GstElementDetails plugin_details =
GST_ELEMENT_DETAILS("SH hardware video encoder",
"Codec/Encoder/Video",
"Encode mpeg-based video stream(mpeg4, h264)",
"Johannes Lahti <[email protected]>");
GstElementClass *element_class = GST_ELEMENT_CLASS(klass);
gst_element_class_add_pad_template(element_class,
gst_static_pad_template_get(&enc_src_factory));
gst_element_class_add_pad_template(element_class,
gst_static_pad_template_get(&enc_sink_factory));
gst_element_class_set_details(element_class, &plugin_details);
}
static void
gst_sh_video_enc_dispose(GObject * object)
{
GstSHVideoEnc *enc = GST_SH_VIDEO_ENC(object);
if (enc->encoder != NULL)
{
shcodecs_encoder_close(enc->encoder);
enc->encoder = NULL;
}
pthread_mutex_destroy(&enc->mutex);
pthread_mutex_destroy(&enc->cond_mutex);
pthread_cond_destroy(&enc->thread_condition);
G_OBJECT_CLASS(parent_class)->dispose(object);
}
static void
gst_sh_video_enc_class_init(GstSHVideoEncClass * klass)
{
GObjectClass *g_object_class;
GstElementClass *gst_element_class;
g_object_class = (GObjectClass *)klass;
gst_element_class = (GstElementClass *)klass;
g_object_class->dispose = gst_sh_video_enc_dispose;
g_object_class->set_property = gst_sh_video_enc_set_property;
g_object_class->get_property = gst_sh_video_enc_get_property;
GST_DEBUG_CATEGORY_INIT(gst_sh_mobile_debug, "gst-sh-mobile-enc",
0, "Encoder for H264/MPEG4 streams");
g_object_class_install_property(g_object_class, PROP_CNTL_FILE,
g_param_spec_string("cntl-file",
"Control file location",
"Location of the file including encoding parameters",
NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_STREAM_TYPE,
g_param_spec_string("stream-type",
"Stream type",
"The type of the stream (h264/mpeg4)",
NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_WIDTH,
g_param_spec_long("width",
"Width",
"Width of the video frame",
0, G_MAXLONG, DEFAULT_WIDTH,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_HEIGHT,
g_param_spec_long("height",
"Height",
"Height of the video frame",
0, G_MAXLONG, DEFAULT_HEIGHT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_FRAMERATE,
g_param_spec_long("framerate",
"Framerate",
"Framerate of the video stream. Multiply with 10 fe. 30fps => 300",
0, G_MAXLONG, DEFAULT_FRAMERATE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_BITRATE,
g_param_spec_long("bitrate",
"Bitrate",
"Bitrate of the video stream",
0, G_MAXLONG, DEFAULT_BITRATE_H264,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_I_VOP_INTERVAL,
g_param_spec_long("i-vop-interval",
"I VOP interval",
"",
0, G_MAXLONG, DEFAULT_I_VOP_INTERVAL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_MV_MODE,
g_param_spec_long("mv-mode",
"MV mode",
"",
0, G_MAXLONG, DEFAULT_MV_MODE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_FCODE_FORWARD,
g_param_spec_long("fcode-forward",
"I VOP interval",
"",
0, G_MAXLONG, DEFAULT_FCODE_FORWARD,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_SEARCH_MODE,
g_param_spec_long("search-mode",
"Search mode",
"",
0, G_MAXLONG, DEFAULT_SEARCH_MODE_H264,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_SEARCH_TIME_FIXED,
g_param_spec_long("search-time-fixed",
"Search time fixed",
"",
0, G_MAXLONG, DEFAULT_SEARCH_TIME_FIXED,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_RATECONTROL_SKIP_ENABLE,
g_param_spec_long("ratecontrol-skip-enable",
"Rate control skip enable",
"",
0, G_MAXLONG, DEFAULT_RATECONTROL_SKIP_ENABLE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_RATECONTROL_USE_PREVQUANT,
g_param_spec_long("ratecontrol-use-prevquant",
"Rate control use prev quant",
"",
0, G_MAXLONG, DEFAULT_RATECONTROL_USE_PREVQUANT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_RATECONTROL_RESPECT_TYPE,
g_param_spec_long("ratecontrol-respect-type",
"Rate control respect type",
"",
0, G_MAXLONG, DEFAULT_RATECONTROL_RESPECT_TYPE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_RATECONTROL_INTRA_THR_CHANGEABLE,
g_param_spec_long("ratecontrol-intra-thr-changeable",
"Rate control intra THR changeable",
"",
0, G_MAXLONG, DEFAULT_RATECONTROL_INTRA_THR_CHANGEABLE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_CONTROL_BITRATE_LENGTH,
g_param_spec_long("control-bitrate-length",
"Control bitrate length",
"",
0, G_MAXLONG, DEFAULT_CONTROL_BITRATE_LENGTH,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_INTRA_MACROBLOCK_REFRESH_CYCLE,
g_param_spec_long("intra-macroblock-refresh-cycle",
"Intra macroblock refresh cycle",
"",
0, G_MAXLONG, DEFAULT_INTRA_MACROBLOCK_REFRESH_CYCLE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_VIDEO_FORMAT,
g_param_spec_long("video-format",
"Video format",
"",
0, G_MAXLONG, DEFAULT_VIDEO_FORMAT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_FRAME_NUM_RESOLUTION,
g_param_spec_long("frame-num-resolution",
"Frame number resolution",
"",
0, G_MAXLONG, DEFAULT_FRAME_NUM_RESOLUTION,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_NOISE_REDUCTION,
g_param_spec_long("noise-reduction",
"Noise reduction",
"",
0, G_MAXLONG, DEFAULT_NOISE_REDUCTION,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_REACTION_PARAM_COEFF,
g_param_spec_long("reaction-param-coeff",
"Reaction parameter coefficient",
"",
0, G_MAXLONG, DEFAULT_REACTION_PARAM_COEFF,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_WEIGHTED_Q_MODE,
g_param_spec_long("weighted-q-mode",
"Weighted Q-mode",
"",
0, G_MAXLONG, DEFAULT_WEIGHTED_Q_MODE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_I_VOP_QUANT_INITIAL_VALUE,
g_param_spec_ulong("i-vop-quant-initial-value",
"I-VOP quantization intitial value",
"",
0, G_MAXULONG, DEFAULT_I_VOP_QUANT_INITIAL_VALUE_H264,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_P_VOP_QUANT_INITIAL_VALUE,
g_param_spec_ulong("p-vop-quant-initial-value",
"P-VOP quantization intitial value",
"",
0, G_MAXULONG, DEFAULT_P_VOP_QUANT_INITIAL_VALUE_H264,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_USE_D_QUANT,
g_param_spec_ulong("use-d-quant",
"Use D-quantization",
"",
0, G_MAXULONG, DEFAULT_USE_D_QUANT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_CLIP_D_QUANT_FRAME,
g_param_spec_ulong("clip-d-quant-frame",
"Clip D-quantized frame",
"",
0, G_MAXULONG, DEFAULT_USE_D_QUANT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_QUANT_MIN,
g_param_spec_ulong("quant-min",
"Minimum quantization",
"",
0, G_MAXULONG, DEFAULT_QUANT_MIN_H264,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_QUANT_MIN_I_VOP_UNDER_RANGE,
g_param_spec_ulong("quant-min-i-vop-under-range",
"",
"",
0, G_MAXULONG, DEFAULT_QUANT_MIN_I_VOP_UNDER_RANGE_H264,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_QUANT_MAX,
g_param_spec_ulong("quant-max",
"Maximum quantization",
"",
0, G_MAXULONG, DEFAULT_QUANT_MAX_H264,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_PARAM_CHANGEABLE,
g_param_spec_ulong("param-changeable",
"",
"",
0, G_MAXULONG, DEFAULT_PARAM_CHANGEABLE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_CHANGEABLE_MAX_BITRATE,
g_param_spec_ulong("changeable-max-bitrate",
"Maximum changeable bitrate",
"",
0, G_MAXULONG, DEFAULT_CHANGEABLE_MAX_BITRATE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
//MPEG4
g_object_class_install_property(g_object_class, PROP_OUT_VOS,
g_param_spec_ulong("out-vos",
"Out VOS",
"",
0, G_MAXULONG, DEFAULT_OUT_VOS,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_OUT_GOV,
g_param_spec_ulong("out-gov",
"Out GOV",
"",
0, G_MAXULONG, DEFAULT_OUT_GOV,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_ASPECT_RATIO_INFO_TYPE,
g_param_spec_ulong("aspect-ratio-info-type",
"Aspect ration info type",
"",
0, G_MAXULONG, DEFAULT_ASPECT_RATIO_INFO_TYPE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_ASPECT_RATIO_INFO_VALUE,
g_param_spec_ulong("aspect-ratio-info-value",
"Aspect ration info value",
"",
0, G_MAXULONG, DEFAULT_ASPECT_RATIO_INFO_VALUE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_VOS_PROFILE_LEVEL_TYPE,
g_param_spec_ulong("vos-profile-level-type",
"VOS proile level type",
"",
0, G_MAXULONG, DEFAULT_VOS_PROFILE_LEVEL_TYPE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_VOS_PROFILE_LEVEL_VALUE,
g_param_spec_ulong("vos-profile-level-value",
"VOS proile level value",
"",
0, G_MAXULONG, DEFAULT_VOS_PROFILE_LEVEL_VALUE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_OUT_VISUAL_OBJECT_IDENTIFIER,
g_param_spec_ulong("out-visual-object-identifier",
"Out visual object identifier",
"",
0, G_MAXULONG, DEFAULT_OUT_VISUAL_OBJECT_IDENTIFIER,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_VISUAL_OBJECT_VERID,
g_param_spec_ulong("visual-object-verid",
"Visual object verid",
"",
0, G_MAXULONG, DEFAULT_VISUAL_OBJECT_VERID,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_VISUAL_OBJECT_PRIORITY,
g_param_spec_ulong("visual-object-priority",
"Visual object priority",
"",
0, G_MAXULONG, DEFAULT_VISUAL_OBJECT_PRIORITY,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_VIDEO_OBJECT_TYPE_INDICATION,
g_param_spec_ulong("visual-object-type-indication",
"Visual object type indication",
"",
0, G_MAXULONG, DEFAULT_VIDEO_OBJECT_TYPE_INDICATION,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_OUT_OBJECT_LAYER_IDENTIFIER,
g_param_spec_ulong("out-object-layer-identifier",
"Out object layer identifier",
"",
0, G_MAXULONG, DEFAULT_OUT_OBJECT_LAYER_IDENTIFIER,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_VIDEO_OBJECT_LAYER_VERID,
g_param_spec_ulong("video-object-layer-verid",
"Video object layer verid",
"",
0, G_MAXULONG, DEFAULT_VIDEO_OBJECT_LAYER_VERID,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_VIDEO_OBJECT_LAYER_PRIORITY,
g_param_spec_ulong("video-object-layer-priority",
"Video object layer priority",
"",
0, G_MAXULONG, DEFAULT_VIDEO_OBJECT_LAYER_PRIORITY,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_ERROR_RESILIENCE_MODE,
g_param_spec_ulong("error-resilience-mode",
"Error resilience mode",
"",
0, G_MAXULONG, DEFAULT_ERROR_RESILIENCE_MODE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_VIDEO_PACKET_SIZE_MB,
g_param_spec_ulong("video-packet-size-mb",
"Video packet size MB",
"",
0, G_MAXULONG, DEFAULT_VIDEO_PACKET_SIZE_MB,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_VIDEO_PACKET_SIZE_BIT,
g_param_spec_ulong("video-packet-size-bit",
"Video packet size bit",
"",
0, G_MAXULONG, DEFAULT_VIDEO_PACKET_SIZE_BIT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_VIDEO_PACKET_HEADER_EXTENTION,
g_param_spec_ulong("video-packet-header-extention",
"Video packet header extention",
"",
0, G_MAXULONG, DEFAULT_VIDEO_PACKET_HEADER_EXTENTION,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_DATA_PARTITIONED,
g_param_spec_ulong("data-partitioned",
"Data partitioned",
"",
0, G_MAXULONG, DEFAULT_DATA_PARTITIONED,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_REVERSIBLE_VLC,
g_param_spec_ulong("reversible-vlc",
"Reversible VLC",
"",
0, G_MAXULONG, DEFAULT_REVERSIBLE_VLC,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_HIGH_QUALITY,
g_param_spec_ulong("high-quality",
"High quality",
"",
0, G_MAXULONG, DEFAULT_HIGH_QUALITY,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_RATECONTROL_VBV_SKIPCHECK_ENABLE,
g_param_spec_ulong("ratecontrol-vbv-skipcheck-enable",
"Rate control VBV skip check enable",
"",
0, G_MAXULONG, DEFAULT_RATECONTROL_VBV_SKIPCHECK_ENABLE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_RATECONTROL_VBV_I_VOP_NOSKIP,
g_param_spec_ulong("ratecontrol-vbv-i-vop-noskip",
"Rate control VBV I-VOP no skip",
"",
0, G_MAXULONG, DEFAULT_RATECONTROL_VBV_I_VOP_NOSKIP,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_RATECONTROL_VBV_REMAIN_ZERO_SKIP_ENABLE,
g_param_spec_ulong("ratecontrol-vbv-remain-zero-skip-enable",
"Rate control VBV remain zero skip enable",
"",
0, G_MAXULONG, DEFAULT_RATECONTROL_VBV_REMAIN_ZERO_SKIP_ENABLE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_RATECONTROL_VBV_BUFFER_UNIT_SIZE,
g_param_spec_ulong("ratecontrol-vbv-buffer-unit-size",
"Rate control VBV buffer unit size",
"",
0, G_MAXULONG, DEFAULT_RATECONTROL_VBV_BUFFER_UNIT_SIZE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_RATECONTROL_VBV_BUFFER_MODE,
g_param_spec_ulong("ratecontrol-vbv-buffer-mode",
"Rate control VBV buffer mode",
"",
0, G_MAXULONG, DEFAULT_RATECONTROL_VBV_BUFFER_MODE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_RATECONTROL_VBV_MAX_SIZE,
g_param_spec_ulong("ratecontrol-vbv-max-size",
"Rate control VBV max size",
"",
0, G_MAXULONG, DEFAULT_RATECONTROL_VBV_MAX_SIZE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_RATECONTROL_VBV_OFFSET,
g_param_spec_ulong("ratecontrol-vbv-offset",
"Rate control VBV offset",
"",
0, G_MAXULONG, DEFAULT_RATECONTROL_VBV_OFFSET,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_RATECONTROL_VBV_OFFSET_RATE,
g_param_spec_ulong("ratecontrol-vbv-offset-rate",
"Rate control VBV offset rate",
"",
0, G_MAXULONG, DEFAULT_RATECONTROL_VBV_OFFSET_RATE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_QUANT_TYPE,
g_param_spec_ulong("quant-type",
"Quantization type",
"",
0, G_MAXULONG, DEFAULT_QUANT_TYPE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_USE_AC_PREDICTION,
g_param_spec_ulong("use-ac-prediction",
"Use AC prediction",
"",
0, G_MAXULONG, DEFAULT_USE_AC_PREDICTION,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property(g_object_class, PROP_VOP_MIN_MODE,
g_param_spec_ulong("vop-min-mode",
"VOP min mode",
"",
0, G_MAXULONG, DEFAULT_VOP_MIN_MODE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));