History

avcodec/hevc_sei: switch to AVBufferRef buffer for a53 caption

Limin Wang committed 6 years ago

Commit dbb05171 parent 99f505d3 files · +16 −17Browse files

Unified · Split

3 files
  1. libavcodec/hevc_sei.c +7 −7
  2. libavcodec/hevc_sei.h +1 −2
  3. libavcodec/hevcdec.c +8 −8
libavcodec/hevc_sei.c+7−7
@@ -177,7 +177,8 @@ static int decode_registered_user_data_closed_caption(HEVCSEIA53Caption *s, GetB · 176 unmodified lines
177 size -= 2;177 size -= 2;
178 178
179 if (cc_count && size >= cc_count * 3) {179 if (cc_count && size >= cc_count * 3) {
180 const uint64_t new_size = (s->a53_caption_size + cc_count180 int old_size = s->buf_ref ? s->buf_ref->size : 0;
181 const uint64_t new_size = (old_size + cc_count
181 * UINT64_C(3));182 * UINT64_C(3));
182 int i, ret;183 int i, ret;
183 184
@@ -185,14 +186,14 @@ static int decode_registered_user_data_closed_caption(HEVCSEIA53Caption *s, GetB · 1 unmodified line
185 return AVERROR(EINVAL);186 return AVERROR(EINVAL);
186 187
187 /* Allow merging of the cc data from two fields. */188 /* Allow merging of the cc data from two fields. */
188 ret = av_reallocp(&s->a53_caption, new_size);189 ret = av_buffer_realloc(&s->buf_ref, new_size);
189 if (ret < 0)190 if (ret < 0)
190 return ret;191 return ret;
191 192
192 for (i = 0; i < cc_count; i++) {193 for (i = 0; i < cc_count; i++) {
193 s->a53_caption[s->a53_caption_size++] = get_bits(gb, 8);194 s->buf_ref->data[old_size++] = get_bits(gb, 8);
194 s->a53_caption[s->a53_caption_size++] = get_bits(gb, 8);195 s->buf_ref->data[old_size++] = get_bits(gb, 8);
195 s->a53_caption[s->a53_caption_size++] = get_bits(gb, 8);196 s->buf_ref->data[old_size++] = get_bits(gb, 8);
196 }197 }
197 skip_bits(gb, 8); // marker_bits198 skip_bits(gb, 8); // marker_bits
198 }199 }
@@ -363,6 +364,5 @@ int ff_hevc_decode_nal_sei(GetBitContext *gb, void *logctx, HEVCSEI *s, · 164 unmodified lines
363 364
364void ff_hevc_reset_sei(HEVCSEI *s)365void ff_hevc_reset_sei(HEVCSEI *s)
365{366{
366 s->a53_caption.a53_caption_size = 0;367 av_buffer_unref(&s->a53_caption.buf_ref);
367 av_freep(&s->a53_caption.a53_caption);
368}368}
libavcodec/hevc_sei.h+1−2
@@ -83,8 +83,7 @@ typedef struct HEVCSEIPictureTiming { · 82 unmodified lines
83} HEVCSEIPictureTiming;83} HEVCSEIPictureTiming;
84 84
85typedef struct HEVCSEIA53Caption {85typedef struct HEVCSEIA53Caption {
86 int a53_caption_size;86 AVBufferRef *buf_ref;
87 uint8_t *a53_caption;
88} HEVCSEIA53Caption;87} HEVCSEIA53Caption;
89 88
90typedef struct HEVCSEIMasteringDisplay {89typedef struct HEVCSEIMasteringDisplay {
libavcodec/hevcdec.c+8−8
@@ -2778,14 +2778,14 @@ static int set_side_data(HEVCContext *s) · 2777 unmodified lines
2778 metadata->MaxCLL, metadata->MaxFALL);2778 metadata->MaxCLL, metadata->MaxFALL);
2779 }2779 }
2780 2780
2781 if (s->sei.a53_caption.a53_caption) {2781 if (s->sei.a53_caption.buf_ref) {
2782 AVFrameSideData* sd = av_frame_new_side_data(out,2782 HEVCSEIA53Caption *a53 = &s->sei.a53_caption;
2783 AV_FRAME_DATA_A53_CC,2783
2784 s->sei.a53_caption.a53_caption_size);2784 AVFrameSideData *sd = av_frame_new_side_data_from_buf(out, AV_FRAME_DATA_A53_CC, a53->buf_ref);
2785 if (sd)2785 if (!sd)
2786 memcpy(sd->data, s->sei.a53_caption.a53_caption, s->sei.a53_caption.a53_caption_size);2786 av_buffer_unref(&a53->buf_ref);
2787 av_freep(&s->sei.a53_caption.a53_caption);2787 a53->buf_ref = NULL;
2788 s->sei.a53_caption.a53_caption_size = 0;2788
2789 s->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;2789 s->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
2790 }2790 }
2791 2791

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t