On Mon, 25 Nov 2013 10:39:08 -0800, John Stebbins <[email protected]> 
wrote:
> ---
>  libavcodec/mpeg12dec.c | 65 
> ++++++++++++++++++++++++++++++++++++++++++++++++++
>  libavutil/frame.h      |  6 +++++
>  2 files changed, 71 insertions(+)
> 
> diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
> index 0e11dda..8fccf2b 100644
> --- a/libavcodec/mpeg12dec.c
> +++ b/libavcodec/mpeg12dec.c
> @@ -44,6 +44,8 @@ typedef struct Mpeg1Context {
>      int mpeg_enc_ctx_allocated; /* true if decoding context allocated */
>      int repeat_field; /* true if we must repeat the field */
>      AVPanScan pan_scan;              /**< some temporary storage for the 
> panscan */
> +    uint8_t *a53_caption;
> +    int a53_caption_size;
>      int slice_count;
>      int save_aspect_info;
>      int save_width, save_height, save_progressive_seq;
> @@ -1529,6 +1531,14 @@ static int mpeg_field_start(MpegEncContext *s, const 
> uint8_t *buf, int buf_size)
>              return AVERROR(ENOMEM);
>          memcpy(pan_scan->data, &s1->pan_scan, sizeof(s1->pan_scan));
>  
> +        if (s1->a53_caption) {
> +            AVFrameSideData *sd = av_frame_new_side_data(
> +                &s->current_picture_ptr->f, AV_FRAME_DATA_A53_CC,
> +                s1->a53_caption_size);
> +            if (sd)
> +                memcpy(sd->data, s1->a53_caption, s1->a53_caption_size);
> +            av_freep(&s1->a53_caption);
> +        }
>          if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_FRAME))
>              ff_thread_finish_setup(avctx);
>      } else { // second field
> @@ -2038,6 +2048,58 @@ static int vcr2_init_sequence(AVCodecContext *avctx)
>  }
>  
>  
> +static int mpeg_decode_a53_cc(AVCodecContext *avctx,
> +                              const uint8_t *p, int buf_size)
> +{
> +    Mpeg1Context *s1 = avctx->priv_data;
> +
> +    if (buf_size >= 6 &&
> +        p[0] == 'G' && p[1] == 'A' && p[2] == '9' && p[3] == '4' &&
> +        p[4] == 3 && (p[5] & 0x40)) {
> +        /* extract A53 Part 4 CC data */
> +        int cc_count = p[5] & 0x1f;
> +        if (cc_count > 0 && buf_size >= 7 + cc_count * 3) {
> +            s1->a53_caption_size = cc_count * 3;
> +            s1->a53_caption = av_malloc(s1->a53_caption_size);

Seems to me this could leak a53_caption remaining from the previous call (if we
never get to mpeg_field_start()), so you should free it to be safe.

Otherwise I think the patch is fine.

-- 
Anton Khirnov
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to