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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
|
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* Copyright (C) <2004> Wim Taymans <wim@fluendo.com>
* Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
*
* 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., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "string.h"
#include "gstlame.h"
#ifdef lame_set_preset
#define GST_LAME_PRESET
#endif
GST_DEBUG_CATEGORY_STATIC (debug);
#define GST_CAT_DEFAULT debug
/* elementfactory information */
static GstElementDetails gst_lame_details = {
"L.A.M.E. mp3 encoder",
"Codec/Encoder/Audio",
"High-quality free MP3 encoder",
"Erik Walthinsen <omega@cse.ogi.edu>, " "Wim Taymans <wim@fluendo.com>",
};
/* LAME can do MPEG-1, MPEG-2, and MPEG-2.5, so it has 9 possible
* sample rates it supports */
static GstStaticPadTemplate gst_lame_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("audio/x-raw-int, "
"endianness = (int) " G_STRINGIFY (G_BYTE_ORDER) ", "
"signed = (boolean) true, "
"width = (int) 16, "
"depth = (int) 16, "
"rate = (int) { 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000 }, "
"channels = (int) [ 1, 2 ]")
);
static GstStaticPadTemplate gst_lame_src_template =
GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("audio/mpeg, "
"mpegversion = (int) 1, "
"layer = (int) 3, "
"rate = (int) { 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000 }, "
"channels = (int) [ 1, 2 ]")
);
/********** Define useful types for non-programmatic interfaces **********/
#define GST_TYPE_LAME_MODE (gst_lame_mode_get_type())
static GType
gst_lame_mode_get_type (void)
{
static GType lame_mode_type = 0;
static GEnumValue lame_modes[] = {
{0, "Stereo", "stereo"},
{1, "Joint Stereo", "joint"},
{2, "Dual Channel", "dual"},
{3, "Mono", "mono"},
{4, "Auto", "auto"},
{0, NULL, NULL}
};
if (!lame_mode_type) {
lame_mode_type = g_enum_register_static ("GstLameMode", lame_modes);
}
return lame_mode_type;
}
#define GST_TYPE_LAME_QUALITY (gst_lame_quality_get_type())
static GType
gst_lame_quality_get_type (void)
{
static GType lame_quality_type = 0;
static GEnumValue lame_quality[] = {
{0, "0 - Best", "0"},
{1, "1", "1"},
{2, "2", "2"},
{3, "3", "3"},
{4, "4", "4"},
{5, "5 - Default", "5"},
{6, "6", "6"},
{7, "7", "7"},
{8, "8", "8"},
{9, "9 - Worst", "9"},
{0, NULL, NULL}
};
if (!lame_quality_type) {
lame_quality_type = g_enum_register_static ("GstLameQuality", lame_quality);
}
return lame_quality_type;
}
#define GST_TYPE_LAME_PADDING (gst_lame_padding_get_type())
static GType
gst_lame_padding_get_type (void)
{
static GType lame_padding_type = 0;
static GEnumValue lame_padding[] = {
{0, "No Padding", "never"},
{1, "Always Pad", "always"},
{2, "Adjust Padding", "adjust"},
{0, NULL, NULL}
};
if (!lame_padding_type) {
lame_padding_type = g_enum_register_static ("GstLamePadding", lame_padding);
}
return lame_padding_type;
}
#define GST_TYPE_LAME_VBRMODE (gst_lame_vbrmode_get_type())
static GType
gst_lame_vbrmode_get_type (void)
{
static GType lame_vbrmode_type = 0;
static GEnumValue lame_vbrmode[] = {
{vbr_off, "No VBR (Constant Bitrate)", "none"},
{vbr_rh, "Lame's old VBR algorithm", "old"},
{vbr_abr, "VBR Average Bitrate", "abr"},
{vbr_mtrh, "Lame's new VBR algorithm", "new"},
{0, NULL, NULL}
};
if (!lame_vbrmode_type) {
lame_vbrmode_type = g_enum_register_static ("GstLameVbrmode", lame_vbrmode);
}
return lame_vbrmode_type;
}
#ifdef GSTLAME_PRESET
#define GST_TYPE_LAME_PRESET (gst_lame_preset_get_type())
static GType
gst_lame_preset_get_type (void)
{
static GType gst_lame_preset = 0;
static GEnumValue gst_lame_presets[] = {
{0, "None", "none"},
{MEDIUM, "Medium", "medium"},
{STANDARD, "Standard", "standard"},
{EXTREME, "Extreme", "extreme"},
{INSANE, "Insane", "insane"},
{0, NULL, NULL}
};
if (!gst_lame_preset) {
gst_lame_preset =
g_enum_register_static ("GstLamePreset", gst_lame_presets);
}
return gst_lame_preset;
}
#endif
/********** Standard stuff for signals and arguments **********/
/* GstLame signals and args */
enum
{
/* FILL_ME */
LAST_SIGNAL
};
enum
{
ARG_0,
ARG_BITRATE,
ARG_COMPRESSION_RATIO,
ARG_QUALITY,
ARG_MODE,
ARG_FORCE_MS,
ARG_FREE_FORMAT,
ARG_COPYRIGHT,
ARG_ORIGINAL,
ARG_ERROR_PROTECTION,
ARG_PADDING_TYPE,
ARG_EXTENSION,
ARG_STRICT_ISO,
ARG_DISABLE_RESERVOIR,
ARG_VBR,
ARG_VBR_MEAN_BITRATE,
ARG_VBR_MIN_BITRATE,
ARG_VBR_MAX_BITRATE,
ARG_VBR_HARD_MIN,
ARG_LOWPASS_FREQ,
ARG_LOWPASS_WIDTH,
ARG_HIGHPASS_FREQ,
ARG_HIGHPASS_WIDTH,
ARG_ATH_ONLY,
ARG_ATH_SHORT,
ARG_NO_ATH,
ARG_ATH_LOWER,
ARG_CWLIMIT,
ARG_ALLOW_DIFF_SHORT,
ARG_NO_SHORT_BLOCKS,
ARG_EMPHASIS,
ARG_VBR_QUALITY,
#ifdef GSTLAME_PRESET
ARG_XINGHEADER, /* FIXME: remove in 0.11 */
ARG_PRESET
#else
ARG_XINGHEADER /* FIXME: remove in 0.11 */
#endif
};
static void gst_lame_base_init (gpointer g_class);
static void gst_lame_class_init (GstLameClass * klass);
static void gst_lame_init (GstLame * gst_lame);
static void gst_lame_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_lame_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static gboolean gst_lame_sink_event (GstPad * pad, GstEvent * event);
static GstFlowReturn gst_lame_chain (GstPad * pad, GstBuffer * buf);
static gboolean gst_lame_setup (GstLame * lame);
static GstStateChangeReturn gst_lame_change_state (GstElement * element,
GstStateChange transition);
static GstElementClass *parent_class = NULL;
/* static guint gst_lame_signals[LAST_SIGNAL] = { 0 }; */
GType
gst_lame_get_type (void)
{
static GType gst_lame_type = 0;
if (!gst_lame_type) {
static const GTypeInfo gst_lame_info = {
sizeof (GstLameClass),
gst_lame_base_init,
NULL,
(GClassInitFunc) gst_lame_class_init,
NULL,
NULL,
sizeof (GstLame),
0,
(GInstanceInitFunc) gst_lame_init,
};
static const GInterfaceInfo tag_setter_info = {
NULL,
NULL,
NULL
};
gst_lame_type =
g_type_register_static (GST_TYPE_ELEMENT, "GstLame", &gst_lame_info, 0);
g_type_add_interface_static (gst_lame_type, GST_TYPE_TAG_SETTER,
&tag_setter_info);
}
return gst_lame_type;
}
static void
gst_lame_release_memory (GstLame * lame)
{
g_slist_foreach (lame->tag_strings, (GFunc) g_free, NULL);
g_slist_free (lame->tag_strings);
lame->tag_strings = NULL;
if (lame->tags) {
gst_tag_list_free (lame->tags);
lame->tags = NULL;
}
if (lame->lgf) {
lame_close (lame->lgf);
lame->lgf = NULL;
}
}
static void
gst_lame_finalize (GObject * obj)
{
gst_lame_release_memory (GST_LAME (obj));
G_OBJECT_CLASS (parent_class)->finalize (obj);
}
static void
gst_lame_base_init (gpointer g_class)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_lame_src_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_lame_sink_template));
gst_element_class_set_details (element_class, &gst_lame_details);
}
static void
gst_lame_class_init (GstLameClass * klass)
{
GObjectClass *gobject_class;
GstElementClass *gstelement_class;
gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
parent_class = g_type_class_peek_parent (klass);
gobject_class->set_property = gst_lame_set_property;
gobject_class->get_property = gst_lame_get_property;
gobject_class->finalize = gst_lame_finalize;
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BITRATE,
g_param_spec_int ("bitrate", "Bitrate (kb/s)", "Bitrate in kbit/sec",
8, 320, 128, G_PARAM_READWRITE));
/* compression ratio set to 0.0 by default otherwise it overrides the bitrate setting */
g_object_class_install_property (G_OBJECT_CLASS (klass),
ARG_COMPRESSION_RATIO, g_param_spec_float ("compression_ratio",
"Compression Ratio",
"let lame choose bitrate to achieve selected compression ratio", 0.0,
200.0, 0.0, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_QUALITY,
g_param_spec_enum ("quality", "Quality",
"Quality of algorithm used for encoding", GST_TYPE_LAME_QUALITY, 5,
G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MODE,
g_param_spec_enum ("mode", "Mode", "Encoding mode", GST_TYPE_LAME_MODE, 0,
G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FORCE_MS,
g_param_spec_boolean ("force_ms", "Force ms",
"Force ms_stereo on all frames", TRUE, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FREE_FORMAT,
g_param_spec_boolean ("free_format", "Free format",
"Produce a free format bitstream", TRUE, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_COPYRIGHT,
g_param_spec_boolean ("copyright", "Copyright", "Mark as copyright", TRUE,
G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ORIGINAL,
g_param_spec_boolean ("original", "Original", "Mark as non-original",
TRUE, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ERROR_PROTECTION,
g_param_spec_boolean ("error_protection", "Error protection",
"Adds 16 bit checksum to every frame", TRUE, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PADDING_TYPE,
g_param_spec_enum ("padding_type", "Padding type", "Padding type",
GST_TYPE_LAME_PADDING, 0, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_EXTENSION,
g_param_spec_boolean ("extension", "Extension", "Extension", TRUE,
G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_STRICT_ISO,
g_param_spec_boolean ("strict_iso", "Strict ISO",
"Comply as much as possible to ISO MPEG spec", TRUE,
G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass),
ARG_DISABLE_RESERVOIR, g_param_spec_boolean ("disable_reservoir",
"Disable reservoir", "Disable the bit reservoir", TRUE,
G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VBR,
g_param_spec_enum ("vbr", "VBR", "Specify bitrate mode",
GST_TYPE_LAME_VBRMODE, vbr_off, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VBR_QUALITY,
g_param_spec_enum ("vbr_quality", "VBR Quality", "VBR Quality",
GST_TYPE_LAME_QUALITY, 5, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VBR_MEAN_BITRATE,
g_param_spec_int ("vbr_mean_bitrate", "VBR mean bitrate",
"Specify mean bitrate", 0, G_MAXINT, 0, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VBR_MIN_BITRATE,
g_param_spec_int ("vbr_min_bitrate", "VBR min bitrate",
"Specify min bitrate", 0, G_MAXINT, 0, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VBR_MAX_BITRATE,
g_param_spec_int ("vbr_max_bitrate", "VBR max bitrate",
"Specify max bitrate", 0, G_MAXINT, 0, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VBR_HARD_MIN,
g_param_spec_int ("vbr_hard_min", "VBR hard min",
"Specify hard min bitrate", 0, G_MAXINT, 0, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LOWPASS_FREQ,
g_param_spec_int ("lowpass_freq", "Lowpass freq",
"frequency(kHz), lowpass filter cutoff above freq", 0, 50000, 0,
G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LOWPASS_WIDTH,
g_param_spec_int ("lowpass_width", "Lowpass width",
"frequency(kHz) - default 15% of lowpass freq", 0, G_MAXINT, 0,
G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_HIGHPASS_FREQ,
g_param_spec_int ("highpass_freq", "Highpass freq",
"frequency(kHz), highpass filter cutoff below freq", 0, 50000, 0,
G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_HIGHPASS_WIDTH,
g_param_spec_int ("highpass_width", "Highpass width",
"frequency(kHz) - default 15% of highpass freq", 0, G_MAXINT, 0,
G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ATH_ONLY,
g_param_spec_boolean ("ath_only", "ATH only",
"Ignore GPSYCHO completely, use ATH only", TRUE, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ATH_SHORT,
g_param_spec_boolean ("ath_short", "ATH short",
"Ignore GPSYCHO for short blocks, use ATH only", TRUE,
G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NO_ATH,
g_param_spec_boolean ("no_ath", "No ath",
"turns ATH down to a flat noise floor", TRUE, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ATH_LOWER,
g_param_spec_int ("ath_lower", "ATH lower", "lowers ATH by x dB",
G_MININT, G_MAXINT, 0, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_CWLIMIT,
g_param_spec_int ("cwlimit", "Cwlimit",
"Compute tonality up to freq (in kHz) default 8.8717", 0, 50000, 0,
G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ALLOW_DIFF_SHORT,
g_param_spec_boolean ("allow_diff_short", "Allow diff short",
"Allow diff short", TRUE, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NO_SHORT_BLOCKS,
g_param_spec_boolean ("no_short_blocks", "No short blocks",
"Do not use short blocks", TRUE, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_EMPHASIS,
g_param_spec_boolean ("emphasis", "Emphasis", "Emphasis", TRUE,
G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_XINGHEADER,
g_param_spec_boolean ("xingheader", "Output Xing Header",
"Output Xing Header (BROKEN, use xingmux instead)",
FALSE, G_PARAM_READWRITE));
#ifdef GSTLAME_PRESET
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PRESET,
g_param_spec_enum ("preset", "Lame Preset", "Lame Preset",
GST_TYPE_LAME_PRESET, 0, G_PARAM_READWRITE));
#endif
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_lame_change_state);
}
static gboolean
gst_lame_sink_setcaps (GstPad * pad, GstCaps * caps)
{
GstLame *lame;
gint out_samplerate;
GstStructure *structure;
GstCaps *othercaps;
lame = GST_LAME (gst_pad_get_parent (pad));
structure = gst_caps_get_structure (caps, 0);
if (!gst_structure_get_int (structure, "rate", &lame->samplerate))
goto no_rate;
if (!gst_structure_get_int (structure, "channels", &lame->num_channels))
goto no_channels;
GST_DEBUG_OBJECT (lame, "sink_setcaps, setting up lame");
if (!gst_lame_setup (lame))
goto setup_failed;
out_samplerate = lame_get_out_samplerate (lame->lgf);
if (out_samplerate == 0)
goto zero_output_rate;
othercaps =
gst_caps_new_simple ("audio/mpeg",
"mpegversion", G_TYPE_INT, 1,
"layer", G_TYPE_INT, 3,
"channels", G_TYPE_INT, lame->num_channels,
"rate", G_TYPE_INT, out_samplerate, NULL);
/* and use these caps */
gst_pad_set_caps (lame->srcpad, othercaps);
gst_caps_unref (othercaps);
gst_object_unref (lame);
return TRUE;
no_rate:
{
GST_ELEMENT_ERROR (lame, CORE, NEGOTIATION, (NULL),
("no rate specified in input"));
gst_object_unref (lame);
return FALSE;
}
no_channels:
{
GST_ELEMENT_ERROR (lame, CORE, NEGOTIATION, (NULL),
("no channels specified in input"));
gst_object_unref (lame);
return FALSE;
}
zero_output_rate:
{
GST_ELEMENT_ERROR (lame, CORE, NEGOTIATION, (NULL),
("lame decided on a zero sample rate"));
gst_object_unref (lame);
return FALSE;
}
setup_failed:
{
GST_ELEMENT_ERROR (lame, CORE, NEGOTIATION, (NULL),
("could not initialize encoder (wrong parameters?)"));
gst_object_unref (lame);
return FALSE;
}
}
static void
gst_lame_init (GstLame * lame)
{
GST_DEBUG_OBJECT (lame, "starting initialization");
lame->sinkpad =
gst_pad_new_from_static_template (&gst_lame_sink_template, "sink");
gst_pad_set_event_function (lame->sinkpad,
GST_DEBUG_FUNCPTR (gst_lame_sink_event));
gst_pad_set_chain_function (lame->sinkpad,
GST_DEBUG_FUNCPTR (gst_lame_chain));
gst_pad_set_setcaps_function (lame->sinkpad,
GST_DEBUG_FUNCPTR (gst_lame_sink_setcaps));
gst_element_add_pad (GST_ELEMENT (lame), lame->sinkpad);
lame->srcpad =
gst_pad_new_from_static_template (&gst_lame_src_template, "src");
gst_element_add_pad (GST_ELEMENT (lame), lame->srcpad);
/* create an encoder state so we can ask about defaults */
lame->lgf = lame_init ();
lame->samplerate = 44100;
lame->num_channels = 2;
lame->setup = FALSE;
lame->bitrate = 128; /* lame_get_brate (lame->lgf);
* => 0/out of range */
lame->compression_ratio = 0.0; /* lame_get_compression_ratio (lame->lgf);
* => 0/out of range ...
* NOTE: 0.0 makes bitrate take precedence */
lame->quality = 5; /* lame_get_quality (lame->lgf);
* => -1/out of range */
lame->mode = lame_get_mode (lame->lgf);
lame->force_ms = lame_get_force_ms (lame->lgf);
lame->free_format = lame_get_free_format (lame->lgf);
lame->copyright = lame_get_copyright (lame->lgf);
lame->original = lame_get_original (lame->lgf);
lame->error_protection = lame_get_error_protection (lame->lgf);
lame->padding_type = lame_get_padding_type (lame->lgf);
lame->extension = lame_get_extension (lame->lgf);
lame->strict_iso = lame_get_strict_ISO (lame->lgf);
lame->disable_reservoir = lame_get_disable_reservoir (lame->lgf);
lame->vbr = vbr_off; /* lame_get_VBR (lame->lgf); */
lame->vbr_quality = 5;
lame->vbr_mean_bitrate = lame_get_VBR_mean_bitrate_kbps (lame->lgf);
lame->vbr_min_bitrate = lame_get_VBR_min_bitrate_kbps (lame->lgf);
lame->vbr_max_bitrate = 0; /* lame_get_VBR_max_bitrate_kbps (lame->lgf);
* => 0/no vbr possible */
lame->vbr_hard_min = lame_get_VBR_hard_min (lame->lgf);
/* lame->lowpass_freq = 50000; lame_get_lowpassfreq (lame->lgf);
* => 0/lowpass on everything ? */
lame->lowpass_freq = 0;
lame->lowpass_width = 0; /* lame_get_lowpasswidth (lame->lgf);
* => -1/out of range */
lame->highpass_freq = lame_get_highpassfreq (lame->lgf);
lame->highpass_width = 0; /* lame_get_highpasswidth (lame->lgf);
* => -1/out of range */
lame->ath_only = lame_get_ATHonly (lame->lgf);
lame->ath_short = lame_get_ATHshort (lame->lgf);
lame->no_ath = lame_get_noATH (lame->lgf);
/* lame->ath_type = lame_get_ATHtype (lame->lgf); */
lame->ath_lower = lame_get_ATHlower (lame->lgf);
lame->cwlimit = 8.8717; /* lame_get_cwlimit (lame->lgf); => 0 */
lame->allow_diff_short = lame_get_allow_diff_short (lame->lgf);
lame->no_short_blocks = TRUE; /* lame_get_no_short_blocks (lame->lgf); */
lame->emphasis = lame_get_emphasis (lame->lgf);
lame->preset = 0;
lame_close (lame->lgf);
lame->lgf = NULL;
lame->tag_strings = NULL;
GST_DEBUG_OBJECT (lame, "done initializing");
}
typedef struct _GstLameTagMatch GstLameTagMatch;
typedef void (*GstLameTagFunc) (lame_global_flags * gfp, const char *value);
struct _GstLameTagMatch
{
gchar *gstreamer_tag;
GstLameTagFunc tag_func;
};
static GstLameTagMatch tag_matches[] = {
{GST_TAG_TITLE, id3tag_set_title},
{GST_TAG_DATE, id3tag_set_year},
{GST_TAG_TRACK_NUMBER, id3tag_set_track},
{GST_TAG_COMMENT, id3tag_set_comment},
{GST_TAG_ARTIST, id3tag_set_artist},
{GST_TAG_ALBUM, id3tag_set_album},
{GST_TAG_GENRE, (GstLameTagFunc) id3tag_set_genre},
{NULL, NULL}
};
static void
add_one_tag (const GstTagList * list, const gchar * tag, gpointer user_data)
{
GstLame *lame;
gchar *value = NULL;
int i = 0;
lame = GST_LAME (user_data);
g_return_if_fail (lame != NULL);
while (tag_matches[i].gstreamer_tag != NULL) {
if (strcmp (tag, tag_matches[i].gstreamer_tag) == 0) {
break;
}
i++;
}
if (tag_matches[i].tag_func == NULL) {
GST_WARNING_OBJECT (lame,
"Couldn't find matching gstreamer tag for \"%s\"", tag);
return;
}
switch (gst_tag_get_type (tag)) {
case G_TYPE_UINT:{
guint ivalue;
if (!gst_tag_list_get_uint (list, tag, &ivalue)) {
GST_WARNING_OBJECT (lame, "Error reading \"%s\" tag value", tag);
return;
}
value = g_strdup_printf ("%u", ivalue);
break;
}
case G_TYPE_STRING:
if (!gst_tag_list_get_string (list, tag, &value)) {
GST_WARNING_OBJECT (lame, "Error reading \"%s\" tag value", tag);
return;
};
break;
default:{
if (strcmp (tag, GST_TAG_DATE) == 0) {
GDate *date = NULL;
if (!gst_tag_list_get_date (list, tag, &date) || date == NULL) {
GST_WARNING_OBJECT (lame, "Error reading \"%s\" tag value", tag);
} else {
value = g_strdup_printf ("%u", g_date_get_year (date));
g_date_free (date);
}
} else {
GST_WARNING_OBJECT (lame, "Couldn't write tag %s", tag);
}
break;
}
}
if (value != NULL && *value != '\0') {
GST_LOG_OBJECT (lame, "Adding tag %s:%s", tag, value);
tag_matches[i].tag_func (lame->lgf, value);
}
/* lame does not copy strings passed to it and expects them
* to be around later, but it does not free them for us either,
* so we just add them to a list and free it later when it's safe */
lame->tag_strings = g_slist_prepend (lame->tag_strings, value);
}
static void
gst_lame_set_metadata (GstLame * lame)
{
const GstTagList *user_tags;
GstTagList *copy;
g_return_if_fail (lame != NULL);
user_tags = gst_tag_setter_get_tag_list (GST_TAG_SETTER (lame));
GST_DEBUG_OBJECT (lame, "lame->tags = %" GST_PTR_FORMAT, lame->tags);
GST_DEBUG_OBJECT (lame, "user tags = %" GST_PTR_FORMAT, user_tags);
if ((lame->tags == NULL) && (user_tags == NULL)) {
return;
}
copy = gst_tag_list_merge (user_tags, lame->tags,
gst_tag_setter_get_tag_merge_mode (GST_TAG_SETTER (lame)));
GST_DEBUG_OBJECT (lame, "merged tags = %" GST_PTR_FORMAT, copy);
gst_tag_list_foreach ((GstTagList *) copy, add_one_tag, lame);
gst_tag_list_free (copy);
}
static void
gst_lame_set_property (GObject * object, guint prop_id, const GValue * value,
GParamSpec * pspec)
{
GstLame *lame;
g_return_if_fail (GST_IS_LAME (object));
lame = GST_LAME (object);
switch (prop_id) {
case ARG_BITRATE:
lame->bitrate = g_value_get_int (value);
break;
case ARG_COMPRESSION_RATIO:
lame->compression_ratio = g_value_get_float (value);
break;
case ARG_QUALITY:
lame->quality = g_value_get_enum (value);
break;
case ARG_MODE:
lame->mode = g_value_get_enum (value);
break;
case ARG_FORCE_MS:
lame->force_ms = g_value_get_boolean (value);
break;
case ARG_FREE_FORMAT:
lame->free_format = g_value_get_boolean (value);
break;
case ARG_COPYRIGHT:
lame->copyright = g_value_get_boolean (value);
break;
case ARG_ORIGINAL:
lame->original = g_value_get_boolean (value);
break;
case ARG_ERROR_PROTECTION:
lame->error_protection = g_value_get_boolean (value);
break;
case ARG_PADDING_TYPE:
lame->padding_type = g_value_get_int (value);
break;
case ARG_EXTENSION:
lame->extension = g_value_get_boolean (value);
break;
case ARG_STRICT_ISO:
lame->strict_iso = g_value_get_boolean (value);
break;
case ARG_DISABLE_RESERVOIR:
lame->disable_reservoir = g_value_get_boolean (value);
break;
case ARG_VBR:
lame->vbr = g_value_get_enum (value);
break;
case ARG_VBR_QUALITY:
lame->vbr_quality = g_value_get_enum (value);
break;
case ARG_VBR_MEAN_BITRATE:
lame->vbr_mean_bitrate = g_value_get_int (value);
break;
case ARG_VBR_MIN_BITRATE:
lame->vbr_min_bitrate = g_value_get_int (value);
break;
case ARG_VBR_MAX_BITRATE:
lame->vbr_max_bitrate = g_value_get_int (value);
break;
case ARG_VBR_HARD_MIN:
lame->vbr_hard_min = g_value_get_int (value);
break;
case ARG_LOWPASS_FREQ:
lame->lowpass_freq = g_value_get_int (value);
break;
case ARG_LOWPASS_WIDTH:
lame->lowpass_width = g_value_get_int (value);
break;
case ARG_HIGHPASS_FREQ:
lame->highpass_freq = g_value_get_int (value);
break;
case ARG_HIGHPASS_WIDTH:
lame->highpass_width = g_value_get_int (value);
break;
case ARG_ATH_ONLY:
lame->ath_only = g_value_get_boolean (value);
break;
case ARG_ATH_SHORT:
lame->ath_short = g_value_get_boolean (value);
break;
case ARG_NO_ATH:
lame->no_ath = g_value_get_boolean (value);
break;
case ARG_ATH_LOWER:
lame->ath_lower = g_value_get_int (value);
break;
case ARG_CWLIMIT:
lame->cwlimit = g_value_get_int (value);
break;
case ARG_ALLOW_DIFF_SHORT:
lame->allow_diff_short = g_value_get_boolean (value);
break;
case ARG_NO_SHORT_BLOCKS:
lame->no_short_blocks = g_value_get_boolean (value);
break;
case ARG_EMPHASIS:
lame->emphasis = g_value_get_boolean (value);
break;
case ARG_XINGHEADER:
break;
#ifdef GSTLAME_PRESET
case ARG_PRESET:
lame->preset = g_value_get_enum (value);
break;
#endif
default:
break;
}
}
static void
gst_lame_get_property (GObject * object, guint prop_id, GValue * value,
GParamSpec * pspec)
{
GstLame *lame;
g_return_if_fail (GST_IS_LAME (object));
lame = GST_LAME (object);
switch (prop_id) {
case ARG_BITRATE:
g_value_set_int (value, lame->bitrate);
break;
case ARG_COMPRESSION_RATIO:
g_value_set_float (value, lame->compression_ratio);
break;
case ARG_QUALITY:
g_value_set_enum (value, lame->quality);
break;
case ARG_MODE:
g_value_set_enum (value, lame->mode);
break;
case ARG_FORCE_MS:
g_value_set_boolean (value, lame->force_ms);
break;
case ARG_FREE_FORMAT:
g_value_set_boolean (value, lame->free_format);
break;
case ARG_COPYRIGHT:
g_value_set_boolean (value, lame->copyright);
break;
case ARG_ORIGINAL:
g_value_set_boolean (value, lame->original);
break;
case ARG_ERROR_PROTECTION:
g_value_set_boolean (value, lame->error_protection);
break;
case ARG_PADDING_TYPE:
g_value_set_enum (value, lame->padding_type);
break;
case ARG_EXTENSION:
g_value_set_boolean (value, lame->extension);
break;
case ARG_STRICT_ISO:
g_value_set_boolean (value, lame->strict_iso);
break;
case ARG_DISABLE_RESERVOIR:
g_value_set_boolean (value, lame->disable_reservoir);
break;
case ARG_VBR:
g_value_set_enum (value, lame->vbr);
break;
case ARG_VBR_QUALITY:
g_value_set_enum (value, lame->vbr_quality);
break;
case ARG_VBR_MEAN_BITRATE:
g_value_set_int (value, lame->vbr_mean_bitrate);
break;
case ARG_VBR_MIN_BITRATE:
g_value_set_int (value, lame->vbr_min_bitrate);
break;
case ARG_VBR_MAX_BITRATE:
g_value_set_int (value, lame->vbr_max_bitrate);
break;
case ARG_VBR_HARD_MIN:
g_value_set_int (value, lame->vbr_hard_min);
break;
case ARG_LOWPASS_FREQ:
g_value_set_int (value, lame->lowpass_freq);
break;
case ARG_LOWPASS_WIDTH:
g_value_set_int (value, lame->lowpass_width);
break;
case ARG_HIGHPASS_FREQ:
g_value_set_int (value, lame->highpass_freq);
break;
case ARG_HIGHPASS_WIDTH:
g_value_set_int (value, lame->highpass_width);
break;
case ARG_ATH_ONLY:
g_value_set_boolean (value, lame->ath_only);
break;
case ARG_ATH_SHORT:
g_value_set_boolean (value, lame->ath_short);
break;
case ARG_NO_ATH:
g_value_set_boolean (value, lame->no_ath);
break;
case ARG_ATH_LOWER:
g_value_set_int (value, lame->ath_lower);
break;
case ARG_CWLIMIT:
g_value_set_int (value, lame->cwlimit);
break;
case ARG_ALLOW_DIFF_SHORT:
g_value_set_boolean (value, lame->allow_diff_short);
break;
case ARG_NO_SHORT_BLOCKS:
g_value_set_boolean (value, lame->no_short_blocks);
break;
case ARG_EMPHASIS:
g_value_set_boolean (value, lame->emphasis);
break;
case ARG_XINGHEADER:
break;
#ifdef GSTLAME_PRESET
case ARG_PRESET:
g_value_set_enum (value, lame->preset);
break;
#endif
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static gboolean
gst_lame_sink_event (GstPad * pad, GstEvent * event)
{
gboolean ret;
GstLame *lame;
lame = GST_LAME (gst_pad_get_parent (pad));
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_EOS:{
GstBuffer *buf;
gint size;
GST_DEBUG_OBJECT (lame, "handling EOS event");
buf = gst_buffer_new_and_alloc (7200);
size = lame_encode_flush (lame->lgf, GST_BUFFER_DATA (buf), 7200);
if (size > 0) {
GST_BUFFER_SIZE (buf) = size;
GST_DEBUG_OBJECT (lame, "pushing final packet of %u bytes", size);
gst_buffer_set_caps (buf, GST_PAD_CAPS (lame->srcpad));
gst_pad_push (lame->srcpad, buf);
} else {
GST_DEBUG_OBJECT (lame, "no final packet (size=%d)", size);
gst_buffer_unref (buf);
}
ret = gst_pad_event_default (pad, event);
break;
}
case GST_EVENT_FLUSH_START:
GST_DEBUG_OBJECT (lame, "handling FLUSH start event");
/* forward event */
ret = gst_pad_push_event (lame->srcpad, event);
break;
case GST_EVENT_FLUSH_STOP:
{
guchar *mp3_data = NULL;
gint mp3_buffer_size, mp3_size = 0;
GST_DEBUG_OBJECT (lame, "handling FLUSH stop event");
/* clear buffers */
mp3_buffer_size = 7200;
mp3_data = g_malloc (mp3_buffer_size);
mp3_size = lame_encode_flush (lame->lgf, mp3_data, mp3_buffer_size);
ret = gst_pad_push_event (lame->srcpad, event);
break;
}
case GST_EVENT_TAG:
GST_DEBUG_OBJECT (lame, "handling TAG event");
if (lame->tags) {
GstTagList *taglist;
gst_event_parse_tag (event, &taglist),
gst_tag_list_insert (lame->tags, taglist,
gst_tag_setter_get_tag_merge_mode (GST_TAG_SETTER (lame)));
} else {
g_assert_not_reached ();
}
ret = gst_pad_push_event (lame->srcpad, event);
break;
default:
ret = gst_pad_event_default (pad, event);
break;
}
gst_object_unref (lame);
return ret;
}
static GstFlowReturn
gst_lame_chain (GstPad * pad, GstBuffer * buf)
{
GstLame *lame;
guchar *mp3_data;
gint mp3_buffer_size, mp3_size;
gint64 duration;
GstFlowReturn result;
gint num_samples;
guint8 *data;
guint size;
lame = GST_LAME (gst_pad_get_parent (pad));
GST_LOG_OBJECT (lame, "entered chain");
if (!lame->setup)
goto not_setup;
data = GST_BUFFER_DATA (buf);
size = GST_BUFFER_SIZE (buf);
num_samples = size / 2;
/* allocate space for output */
mp3_buffer_size = 1.25 * num_samples + 7200;
mp3_data = g_malloc (mp3_buffer_size);
/* lame seems to be too stupid to get mono interleaved going */
if (lame->num_channels == 1) {
mp3_size = lame_encode_buffer (lame->lgf,
(short int *) data,
(short int *) data, num_samples, mp3_data, mp3_buffer_size);
} else {
mp3_size = lame_encode_buffer_interleaved (lame->lgf,
(short int *) data,
num_samples / lame->num_channels, mp3_data, mp3_buffer_size);
}
GST_LOG_OBJECT (lame, "encoded %d bytes of audio to %d bytes of mp3",
GST_BUFFER_SIZE (buf), mp3_size);
duration = gst_util_uint64_scale_int (size, GST_SECOND,
2 * lame->samplerate * lame->num_channels);
if (GST_BUFFER_DURATION (buf) != GST_CLOCK_TIME_NONE &&
GST_BUFFER_DURATION (buf) != duration)
GST_DEBUG_OBJECT (lame, "incoming buffer had incorrect duration %"
GST_TIME_FORMAT "outgoing buffer will have correct duration %"
GST_TIME_FORMAT,
GST_TIME_ARGS (GST_BUFFER_DURATION (buf)), GST_TIME_ARGS (duration));
if (lame->last_ts == GST_CLOCK_TIME_NONE) {
lame->last_ts = GST_BUFFER_TIMESTAMP (buf);
lame->last_offs = GST_BUFFER_OFFSET (buf);
lame->last_duration = duration;
} else {
lame->last_duration += duration;
}
gst_buffer_unref (buf);
if (mp3_size < 0) {
g_warning ("error %d", mp3_size);
}
if (mp3_size > 0) {
GstBuffer *outbuf;
outbuf = gst_buffer_new ();
GST_BUFFER_DATA (outbuf) = mp3_data;
GST_BUFFER_MALLOCDATA (outbuf) = mp3_data;
GST_BUFFER_SIZE (outbuf) = mp3_size;
GST_BUFFER_TIMESTAMP (outbuf) = lame->last_ts;
GST_BUFFER_OFFSET (outbuf) = lame->last_offs;
GST_BUFFER_DURATION (outbuf) = lame->last_duration;
gst_buffer_set_caps (outbuf, GST_PAD_CAPS (lame->srcpad));
result = gst_pad_push (lame->srcpad, outbuf);
lame->last_ts = GST_CLOCK_TIME_NONE;
} else {
g_free (mp3_data);
result = GST_FLOW_OK;
}
gst_object_unref (lame);
return result;
/* ERRORS */
not_setup:
{
gst_buffer_unref (buf);
GST_ELEMENT_ERROR (lame, CORE, NEGOTIATION, (NULL),
("encoder not initialized (input is not audio?)"));
gst_object_unref (lame);
return GST_FLOW_ERROR;
}
}
/* set up the encoder state */
static gboolean
gst_lame_setup (GstLame * lame)
{
#define CHECK_ERROR(command) G_STMT_START {\
if ((command) < 0) { \
GST_ERROR_OBJECT (lame, "setup failed: " G_STRINGIFY (command)); \
return FALSE; \
} \
}G_STMT_END
int retval;
GST_DEBUG_OBJECT (lame, "starting setup");
/* check if we're already setup; if we are, we might want to check
* if this initialization is compatible with the previous one */
/* FIXME: do this */
if (lame->setup) {
GST_WARNING_OBJECT (lame, "already setup");
lame->setup = FALSE;
}
lame->lgf = lame_init ();
id3tag_init (lame->lgf);
/* let lame choose a default samplerate */
lame_set_out_samplerate (lame->lgf, 0);
/* copy the parameters over */
lame_set_in_samplerate (lame->lgf, lame->samplerate);
/* force mono encoding if we only have one channel */
if (lame->num_channels == 1)
lame->mode = 3;
CHECK_ERROR (lame_set_num_channels (lame->lgf, lame->num_channels));
CHECK_ERROR (lame_set_brate (lame->lgf, lame->bitrate));
CHECK_ERROR (lame_set_compression_ratio (lame->lgf, lame->compression_ratio));
CHECK_ERROR (lame_set_quality (lame->lgf, lame->quality));
CHECK_ERROR (lame_set_mode (lame->lgf, lame->mode));
CHECK_ERROR (lame_set_force_ms (lame->lgf, lame->force_ms));
CHECK_ERROR (lame_set_free_format (lame->lgf, lame->free_format));
CHECK_ERROR (lame_set_copyright (lame->lgf, lame->copyright));
CHECK_ERROR (lame_set_original (lame->lgf, lame->original));
CHECK_ERROR (lame_set_error_protection (lame->lgf, lame->error_protection));
CHECK_ERROR (lame_set_padding_type (lame->lgf, lame->padding_type));
CHECK_ERROR (lame_set_extension (lame->lgf, lame->extension));
CHECK_ERROR (lame_set_strict_ISO (lame->lgf, lame->strict_iso));
CHECK_ERROR (lame_set_disable_reservoir (lame->lgf, lame->disable_reservoir));
CHECK_ERROR (lame_set_VBR (lame->lgf, lame->vbr));
CHECK_ERROR (lame_set_VBR_q (lame->lgf, lame->vbr_quality));
CHECK_ERROR (lame_set_VBR_mean_bitrate_kbps (lame->lgf,
lame->vbr_mean_bitrate));
CHECK_ERROR (lame_set_VBR_min_bitrate_kbps (lame->lgf,
lame->vbr_min_bitrate));
CHECK_ERROR (lame_set_VBR_max_bitrate_kbps (lame->lgf,
lame->vbr_max_bitrate));
CHECK_ERROR (lame_set_VBR_hard_min (lame->lgf, lame->vbr_hard_min));
CHECK_ERROR (lame_set_lowpassfreq (lame->lgf, lame->lowpass_freq));
CHECK_ERROR (lame_set_lowpasswidth (lame->lgf, lame->lowpass_width));
CHECK_ERROR (lame_set_highpassfreq (lame->lgf, lame->highpass_freq));
CHECK_ERROR (lame_set_highpasswidth (lame->lgf, lame->highpass_width));
CHECK_ERROR (lame_set_ATHonly (lame->lgf, lame->ath_only));
CHECK_ERROR (lame_set_ATHshort (lame->lgf, lame->ath_short));
CHECK_ERROR (lame_set_noATH (lame->lgf, lame->no_ath));
CHECK_ERROR (lame_set_ATHlower (lame->lgf, lame->ath_lower));
CHECK_ERROR (lame_set_cwlimit (lame->lgf, lame->cwlimit));
CHECK_ERROR (lame_set_allow_diff_short (lame->lgf, lame->allow_diff_short));
CHECK_ERROR (lame_set_no_short_blocks (lame->lgf, lame->no_short_blocks));
CHECK_ERROR (lame_set_emphasis (lame->lgf, lame->emphasis));
#ifdef GSTLAME_PRESET
if (lame->preset > 0) {
CHECK_ERROR (lame_set_preset (lame->lgf, lame->preset));
}
#endif
gst_lame_set_metadata (lame);
/* initialize the lame encoder */
if ((retval = lame_init_params (lame->lgf)) >= 0) {
lame->setup = TRUE;
/* FIXME: it would be nice to print out the mode here */
GST_INFO ("lame encoder setup (%d kbit/s, %d Hz, %d channels)",
lame->bitrate, lame->samplerate, lame->num_channels);
} else {
GST_ERROR_OBJECT (lame, "lame_init_params returned %d", retval);
}
GST_DEBUG_OBJECT (lame, "done with setup");
return lame->setup;
#undef CHECK_ERROR
}
static GstStateChangeReturn
gst_lame_change_state (GstElement * element, GstStateChange transition)
{
GstLame *lame;
GstStateChangeReturn result;
lame = GST_LAME (element);
switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY:
lame->tags = gst_tag_list_new ();
case GST_STATE_CHANGE_READY_TO_PAUSED:
lame->last_ts = GST_CLOCK_TIME_NONE;
break;
default:
break;
}
result = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
switch (transition) {
case GST_STATE_CHANGE_READY_TO_NULL:
gst_lame_release_memory (lame);
break;
default:
break;
}
return result;
}
static gboolean
plugin_init (GstPlugin * plugin)
{
if (!gst_element_register (plugin, "lame", GST_RANK_NONE, GST_TYPE_LAME))
return FALSE;
GST_DEBUG_CATEGORY_INIT (debug, "lame", 0, "lame mp3 encoder");
return TRUE;
}
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
"lame",
"Encode MP3's with LAME",
plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
|