[FFmpeg-cvslog] avformat/matroskaenc: Combine checks for audio

Andreas Rheinhardt git at videolan.org
Thu Apr 2 21:37:29 EEST 2020


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at gmail.com> | Fri Jan 17 20:14:24 2020 +0100| [0d4b3b4c023b1b13a78e650f81845fb8e25f456c] | committer: Andreas Rheinhardt

avformat/matroskaenc: Combine checks for audio

mkv_write_track() currently has three places where it checks for whether
the current codec type is audio: One in a switch and two outside of it.
These checks can be combined by moving the code after the other two checks
inside the audio-related part of the switch.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0d4b3b4c023b1b13a78e650f81845fb8e25f456c
---

 libavformat/matroskaenc.c | 59 +++++++++++++++++++++++------------------------
 1 file changed, 29 insertions(+), 30 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 832b272033..ec9f4cfdf4 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -1091,7 +1091,7 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv,
     ebml_master subinfo, track;
     int native_id = 0;
     int qt_id = 0;
-    int bit_depth = av_get_bits_per_sample(par->codec_id);
+    int bit_depth;
     int sample_rate = par->sample_rate;
     int output_sample_rate = 0;
     int display_width_div = 1;
@@ -1104,17 +1104,6 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv,
         return 0;
     }
 
-    if (par->codec_type == AVMEDIA_TYPE_AUDIO) {
-        if (!bit_depth && par->codec_id != AV_CODEC_ID_ADPCM_G726) {
-            if (par->bits_per_raw_sample)
-                bit_depth = par->bits_per_raw_sample;
-            else
-                bit_depth = av_get_bytes_per_sample(par->format) << 3;
-        }
-        if (!bit_depth)
-            bit_depth = par->bits_per_coded_sample;
-    }
-
     if (par->codec_id == AV_CODEC_ID_AAC) {
         ret = get_aac_sample_rates(s, par->extradata, par->extradata_size, &sample_rate,
                                    &output_sample_rate);
@@ -1201,24 +1190,6 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv,
         }
     }
 
-    if (par->codec_type == AVMEDIA_TYPE_AUDIO && par->initial_padding && par->codec_id == AV_CODEC_ID_OPUS) {
-        int64_t codecdelay = av_rescale_q(par->initial_padding,
-                                          (AVRational){ 1, 48000 },
-                                          (AVRational){ 1, 1000000000 });
-        if (codecdelay < 0) {
-            av_log(s, AV_LOG_ERROR, "Initial padding is invalid\n");
-            return AVERROR(EINVAL);
-        }
-//         mkv->tracks[i].ts_offset = av_rescale_q(par->initial_padding,
-//                                                 (AVRational){ 1, par->sample_rate },
-//                                                 st->time_base);
-
-        put_ebml_uint(pb, MATROSKA_ID_CODECDELAY, codecdelay);
-    }
-    if (par->codec_id == AV_CODEC_ID_OPUS) {
-        put_ebml_uint(pb, MATROSKA_ID_SEEKPREROLL, OPUS_SEEK_PREROLL);
-    }
-
     switch (par->codec_type) {
     case AVMEDIA_TYPE_VIDEO:
         mkv->have_video = 1;
@@ -1312,6 +1283,24 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv,
         break;
 
     case AVMEDIA_TYPE_AUDIO:
+        if (par->initial_padding && par->codec_id == AV_CODEC_ID_OPUS) {
+        int64_t codecdelay = av_rescale_q(par->initial_padding,
+                                          (AVRational){ 1, 48000 },
+                                          (AVRational){ 1, 1000000000 });
+        if (codecdelay < 0) {
+            av_log(s, AV_LOG_ERROR, "Initial padding is invalid\n");
+            return AVERROR(EINVAL);
+        }
+//         mkv->tracks[i].ts_offset = av_rescale_q(par->initial_padding,
+//                                                 (AVRational){ 1, par->sample_rate },
+//                                                 st->time_base);
+
+        put_ebml_uint(pb, MATROSKA_ID_CODECDELAY, codecdelay);
+    }
+    if (par->codec_id == AV_CODEC_ID_OPUS) {
+        put_ebml_uint(pb, MATROSKA_ID_SEEKPREROLL, OPUS_SEEK_PREROLL);
+    }
+
         put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, MATROSKA_TRACK_TYPE_AUDIO);
 
         if (!native_id)
@@ -1325,6 +1314,16 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv,
         put_ebml_float (pb, MATROSKA_ID_AUDIOSAMPLINGFREQ, sample_rate);
         if (output_sample_rate)
             put_ebml_float(pb, MATROSKA_ID_AUDIOOUTSAMPLINGFREQ, output_sample_rate);
+
+        bit_depth = av_get_bits_per_sample(par->codec_id);
+        if (!bit_depth && par->codec_id != AV_CODEC_ID_ADPCM_G726) {
+            if (par->bits_per_raw_sample)
+                bit_depth = par->bits_per_raw_sample;
+            else
+                bit_depth = av_get_bytes_per_sample(par->format) << 3;
+        }
+        if (!bit_depth)
+            bit_depth = par->bits_per_coded_sample;
         if (bit_depth)
             put_ebml_uint(pb, MATROSKA_ID_AUDIOBITDEPTH, bit_depth);
         end_ebml_master(pb, subinfo);



More information about the ffmpeg-cvslog mailing list