diff mbox

[FFmpeg-devel] avformat/mxfdec: do not use sound essence descriptor quantization bits for bits_per_coded_sample

Message ID 20180826195147.2941-1-cus@passwd.hu
State Accepted
Commit 6aaf1b504c6a0e0e5e2f4c97712b0f83a4115e10
Headers show

Commit Message

Marton Balint Aug. 26, 2018, 7:51 p.m. UTC
It refers to the uncompressed quantization, therefore is not correct for AAC.

Also change mxf_set_pts to work based on current edit unit if
bits_per_coded_sample is not available.

Fixes error messages in the sample of ticket #7366.

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavformat/mxfdec.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Comments

Marton Balint Sept. 1, 2018, 8:13 p.m. UTC | #1
On Sun, 26 Aug 2018, Marton Balint wrote:

> It refers to the uncompressed quantization, therefore is not correct for AAC.
>
> Also change mxf_set_pts to work based on current edit unit if
> bits_per_coded_sample is not available.
>
> Fixes error messages in the sample of ticket #7366.

Ping, will push soon.

Regards,
Marton

>
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
> libavformat/mxfdec.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
> index 8e1089620f..134f27784b 100644
> --- a/libavformat/mxfdec.c
> +++ b/libavformat/mxfdec.c
> @@ -2390,7 +2390,6 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
>             if (st->codecpar->codec_id == AV_CODEC_ID_NONE || (st->codecpar->codec_id == AV_CODEC_ID_PCM_ALAW && (enum AVCodecID)container_ul->id != AV_CODEC_ID_NONE))
>                 st->codecpar->codec_id = (enum AVCodecID)container_ul->id;
>             st->codecpar->channels = descriptor->channels;
> -            st->codecpar->bits_per_coded_sample = descriptor->bits_per_sample;
>
>             if (descriptor->sample_rate.den > 0) {
>                 st->codecpar->sample_rate = descriptor->sample_rate.num / descriptor->sample_rate.den;
> @@ -2423,6 +2422,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
>             } else if (st->codecpar->codec_id == AV_CODEC_ID_MP2) {
>                 st->need_parsing = AVSTREAM_PARSE_FULL;
>             }
> +            st->codecpar->bits_per_coded_sample = av_get_bits_per_sample(st->codecpar->codec_id);
>         } else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA) {
>             enum AVMediaType type;
>             container_ul = mxf_get_codec_ul(mxf_data_essence_container_uls, essence_container_ul);
> @@ -3269,7 +3269,8 @@ static int64_t mxf_set_current_edit_unit(MXFContext *mxf, AVStream *st, int64_t
> static int mxf_set_audio_pts(MXFContext *mxf, AVCodecParameters *par,
>                              AVPacket *pkt)
> {
> -    MXFTrack *track = mxf->fc->streams[pkt->stream_index]->priv_data;
> +    AVStream *st = mxf->fc->streams[pkt->stream_index];
> +    MXFTrack *track = st->priv_data;
>     int64_t bits_per_sample = par->bits_per_coded_sample;
>
>     if (!bits_per_sample)
> @@ -3280,8 +3281,10 @@ static int mxf_set_audio_pts(MXFContext *mxf, AVCodecParameters *par,
>     if (   par->channels <= 0
>         || bits_per_sample <= 0
>         || par->channels * (int64_t)bits_per_sample < 8)
> -        return AVERROR(EINVAL);
> -    track->sample_count += pkt->size / (par->channels * (int64_t)bits_per_sample / 8);
> +        track->sample_count = mxf_compute_sample_count(mxf, st, av_rescale_q(track->sample_count, st->time_base, av_inv_q(track->edit_rate)) + 1);
> +    else
> +        track->sample_count += pkt->size / (par->channels * (int64_t)bits_per_sample / 8);
> +
>     return 0;
> }
> 
> -- 
> 2.16.4
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Marton Balint Sept. 5, 2018, 8:42 p.m. UTC | #2
On Sat, 1 Sep 2018, Marton Balint wrote:

>
> On Sun, 26 Aug 2018, Marton Balint wrote:
>
>> It refers to the uncompressed quantization, therefore is not correct for 
> AAC.
>>
>> Also change mxf_set_pts to work based on current edit unit if
>> bits_per_coded_sample is not available.
>>
>> Fixes error messages in the sample of ticket #7366.
>
> Ping, will push soon.

Pushed.

Regards,
Marton
diff mbox

Patch

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 8e1089620f..134f27784b 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -2390,7 +2390,6 @@  static int mxf_parse_structural_metadata(MXFContext *mxf)
             if (st->codecpar->codec_id == AV_CODEC_ID_NONE || (st->codecpar->codec_id == AV_CODEC_ID_PCM_ALAW && (enum AVCodecID)container_ul->id != AV_CODEC_ID_NONE))
                 st->codecpar->codec_id = (enum AVCodecID)container_ul->id;
             st->codecpar->channels = descriptor->channels;
-            st->codecpar->bits_per_coded_sample = descriptor->bits_per_sample;
 
             if (descriptor->sample_rate.den > 0) {
                 st->codecpar->sample_rate = descriptor->sample_rate.num / descriptor->sample_rate.den;
@@ -2423,6 +2422,7 @@  static int mxf_parse_structural_metadata(MXFContext *mxf)
             } else if (st->codecpar->codec_id == AV_CODEC_ID_MP2) {
                 st->need_parsing = AVSTREAM_PARSE_FULL;
             }
+            st->codecpar->bits_per_coded_sample = av_get_bits_per_sample(st->codecpar->codec_id);
         } else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA) {
             enum AVMediaType type;
             container_ul = mxf_get_codec_ul(mxf_data_essence_container_uls, essence_container_ul);
@@ -3269,7 +3269,8 @@  static int64_t mxf_set_current_edit_unit(MXFContext *mxf, AVStream *st, int64_t
 static int mxf_set_audio_pts(MXFContext *mxf, AVCodecParameters *par,
                              AVPacket *pkt)
 {
-    MXFTrack *track = mxf->fc->streams[pkt->stream_index]->priv_data;
+    AVStream *st = mxf->fc->streams[pkt->stream_index];
+    MXFTrack *track = st->priv_data;
     int64_t bits_per_sample = par->bits_per_coded_sample;
 
     if (!bits_per_sample)
@@ -3280,8 +3281,10 @@  static int mxf_set_audio_pts(MXFContext *mxf, AVCodecParameters *par,
     if (   par->channels <= 0
         || bits_per_sample <= 0
         || par->channels * (int64_t)bits_per_sample < 8)
-        return AVERROR(EINVAL);
-    track->sample_count += pkt->size / (par->channels * (int64_t)bits_per_sample / 8);
+        track->sample_count = mxf_compute_sample_count(mxf, st, av_rescale_q(track->sample_count, st->time_base, av_inv_q(track->edit_rate)) + 1);
+    else
+        track->sample_count += pkt->size / (par->channels * (int64_t)bits_per_sample / 8);
+
     return 0;
 }