From 53f6f28be0084f543e981e98f789087923df2747 Mon Sep 17 00:00:00 2001
From: "Gregorio Gervasio, Jr" <gregorio.gervasio@gmail.com>
Date: Sat, 1 Oct 2016 22:48:04 -0700
Subject: [PATCH 2/2] Added decoding of A53 captions.
---
mythtv/libs/libmythtv/avformatdecoder.cpp | 24 ++++++++++++++++++++----
mythtv/libs/libmythtv/avformatdecoder.h | 1 +
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/mythtv/libs/libmythtv/avformatdecoder.cpp b/mythtv/libs/libmythtv/avformatdecoder.cpp
index c7a375a..6e675ac 100644
a
|
b
|
void AvFormatDecoder::DecodeDTVCC(const uint8_t *buf, uint len, bool scte) |
3002 | 3002 | if (len < 2+(3*cc_count)) |
3003 | 3003 | return; |
3004 | 3004 | |
| 3005 | DecodeCCx08(buf+2, cc_count*3, scte); |
| 3006 | } |
| 3007 | |
| 3008 | void AvFormatDecoder::DecodeCCx08(const uint8_t *buf, uint len, bool scte) |
| 3009 | { |
| 3010 | if (!len) |
| 3011 | return; |
| 3012 | |
3005 | 3013 | bool had_608 = false, had_708 = false; |
3006 | | for (uint cur = 0; cur < cc_count; cur++) |
| 3014 | for (uint cur = 0; cur < len; cur += 3) |
3007 | 3015 | { |
3008 | | uint cc_code = buf[2+(cur*3)]; |
| 3016 | uint cc_code = buf[cur]; |
3009 | 3017 | bool cc_valid = cc_code & 0x04; |
3010 | 3018 | |
3011 | | uint data1 = buf[3+(cur*3)]; |
3012 | | uint data2 = buf[4+(cur*3)]; |
| 3019 | uint data1 = buf[cur+1]; |
| 3020 | uint data2 = buf[cur+2]; |
3013 | 3021 | uint data = (data2 << 8) | data1; |
3014 | 3022 | uint cc_type = cc_code & 0x03; |
3015 | 3023 | uint field; |
… |
… |
bool AvFormatDecoder::ProcessVideoFrame(AVStream *stream, AVFrame *mpa_pic) |
3695 | 3703 | for (uint i = 0; i < cc_len; i += ((cc_buf[i] & 0x1f) * 3) + 2) |
3696 | 3704 | DecodeDTVCC(cc_buf + i, cc_len - i, scte); |
3697 | 3705 | |
| 3706 | if (cc_len == 0) { |
| 3707 | // look for A53 captions |
| 3708 | AVFrameSideData *side_data = av_frame_get_side_data(mpa_pic, AV_FRAME_DATA_A53_CC); |
| 3709 | if (side_data && (side_data->size > 0)) { |
| 3710 | DecodeCCx08(side_data->data, side_data->size, false); |
| 3711 | } |
| 3712 | } |
| 3713 | |
3698 | 3714 | VideoFrame *picframe = (VideoFrame *)(mpa_pic->opaque); |
3699 | 3715 | |
3700 | 3716 | if (FlagIsSet(kDecodeNoDecode)) |
diff --git a/mythtv/libs/libmythtv/avformatdecoder.h b/mythtv/libs/libmythtv/avformatdecoder.h
index 8fcc047..cc23957 100644
a
|
b
|
class AvFormatDecoder : public DecoderBase |
216 | 216 | friend int close_avf(URLContext *h); |
217 | 217 | |
218 | 218 | void DecodeDTVCC(const uint8_t *buf, uint buf_size, bool scte); |
| 219 | void DecodeCCx08(const uint8_t *buf, uint buf_size, bool scte); |
219 | 220 | void InitByteContext(bool forceseek = false); |
220 | 221 | void InitVideoCodec(AVStream *stream, AVCodecContext *enc, |
221 | 222 | bool selectedStream = false); |