Ticket #2481: dvb-na-cc-r11310.patch

File dvb-na-cc-r11310.patch, 6.6 KB (added by kenny@…, 18 years ago)

Revision 1 of MPEG user data CC patch.

  • libs/libmythtv/avformatdecoder.cpp

     
    29542954                        DecodeDTVCC(mpa_pic.atsc_cc_buf + i);
    29552955                    }
    29562956
     2957                    // Decode DVB captions from MPEG user data
     2958                    if (mpa_pic.dvb_cc_len > 0) {
     2959                        unsigned long long utc = lastccptsu;
     2960
     2961                        for (uint i = 0; i < (uint)mpa_pic.dvb_cc_len; i += 2) {
     2962                            uint8_t cc_lo = mpa_pic.dvb_cc_data[i];
     2963                            uint8_t cc_hi = mpa_pic.dvb_cc_data[i+1];
     2964
     2965                            uint16_t cc_dt = (cc_hi << 8) | cc_lo;
     2966
     2967                            if (cc608_good_parity(cc608_parity_table, cc_dt)) {
     2968                                ccd608->FormatCCField(utc/1000, 0, cc_dt);
     2969                                utc += 33367;
     2970                            }
     2971                        }
     2972                        lastccptsu = utc;
     2973                    }
     2974
    29572975                    VideoFrame *picframe = (VideoFrame *)(mpa_pic.opaque);
    29582976
    29592977                    if (!directrendering)
  • libs/libavcodec/mpegvideo.c

     
    15481548        pic->atsc_cc_len = s->tmp_atsc_cc_len;
    15491549        s->tmp_atsc_cc_len = 0;
    15501550
     1551        /* Put DVB captions cached from parse_user_data into the correct frame */
     1552        memcpy(pic->dvb_cc_data, s->tmp_dvb_cc_data, s->tmp_dvb_cc_len);
     1553        pic->dvb_cc_len = s->tmp_dvb_cc_len;
     1554        s->tmp_dvb_cc_len = 0;
     1555
    15511556        pic->reference= (s->pict_type != B_TYPE || s->codec_id == CODEC_ID_H264)
    15521557                        && !s->dropable ? 3 : 0;
    15531558
  • libs/libavcodec/mpegvideo.h

     
    707707    uint8_t tmp_atsc_cc_buf[ATSC_CC_BUF_SIZE];
    708708    int     tmp_atsc_cc_len;
    709709
     710#define DVB_CC_BUF_SIZE 32
     711    /// Used to hold cached user_data about certain types of DVB captions
     712    uint8_t tmp_dvb_cc_data[DVB_CC_BUF_SIZE];
     713    int     tmp_dvb_cc_len;
     714    uint8_t tmp_dvb_p_buf[DVB_CC_BUF_SIZE];
     715    int     tmp_dvb_p_len;
     716
    710717    int (*decode_mb)(struct MpegEncContext *s, DCTELEM block[6][64]); // used by some codecs to avoid a switch()
    711718#define SLICE_OK         0
    712719#define SLICE_ERROR     -1
  • libs/libavcodec/mpeg12.c

     
    30143014        else if (user_data_type_code == 0x06) {
    30153015            // bar data (letterboxing info)
    30163016        }
     3017    } else if (len >= 11 &&
     3018               p[0] == 0x05 && p[1] == 0x02) {
     3019        p += 2;
     3020        len -= 2;
     3021
     3022        Mpeg1Context   *s1 = avctx->priv_data;
     3023        MpegEncContext *s  = &s1->mpeg_enc_ctx;
     3024
     3025        uint8_t dvb_cc_type = p[5];
     3026
     3027        p += 6;
     3028        len -= 6;
     3029
     3030        if (dvb_cc_type == 0x02) { /* 2-byte caption, can be repeated */
     3031            uint8_t hi = p[1];
     3032            uint8_t lo = p[2];
     3033
     3034            dvb_cc_type = p[3];
     3035
     3036            if ((2 <= len) && ((2 + s->tmp_dvb_cc_len) < DVB_CC_BUF_SIZE)) {
     3037                s->tmp_dvb_cc_data[s->tmp_dvb_cc_len++] = hi;
     3038                s->tmp_dvb_cc_data[s->tmp_dvb_cc_len++] = lo;
     3039
     3040                /* Only repeat characters when the next type flag
     3041                 * is 0x04 and the characters are repeatable (i.e., less than
     3042                 * 32 with the parity stripped).
     3043                 */
     3044                if (dvb_cc_type == 0x04 && (hi & 0x7f) < 32) {
     3045                    if ((4 <= len) &&
     3046                        ((4 + s->tmp_dvb_cc_len) < DVB_CC_BUF_SIZE)) {
     3047                        s->tmp_dvb_cc_data[s->tmp_dvb_cc_len++] = hi;
     3048                        s->tmp_dvb_cc_data[s->tmp_dvb_cc_len++] = lo;
     3049                    }
     3050                }
     3051            }
     3052
     3053            p += 6;
     3054            len -= 6;
     3055        } else if (dvb_cc_type == 0x04) { /* 4-byte caption, not repeated */
     3056            if ((4 <= len) && ((4 + s->tmp_dvb_cc_len) < DVB_CC_BUF_SIZE)) {
     3057                s->tmp_dvb_cc_data[s->tmp_dvb_cc_len++] = p[1];
     3058                s->tmp_dvb_cc_data[s->tmp_dvb_cc_len++] = p[2];
     3059                s->tmp_dvb_cc_data[s->tmp_dvb_cc_len++] = p[3];
     3060                s->tmp_dvb_cc_data[s->tmp_dvb_cc_len++] = p[4];
     3061            }
     3062
     3063            p += 9;
     3064            len -= 9;
     3065        } else if (dvb_cc_type == 0x05) {
     3066            /* Buffered prediction frame captions */
     3067            if (s->tmp_dvb_p_len > 0) {
     3068                int i;
     3069                for (i = 0; i < s->tmp_dvb_p_len; i++) {
     3070                    s->tmp_dvb_cc_data[s->tmp_dvb_cc_len++] =
     3071                        s->tmp_dvb_p_buf[i];
     3072                }
     3073                s->tmp_dvb_p_len = 0;
     3074            }
     3075
     3076            dvb_cc_type = p[6];
     3077
     3078            uint8_t hi = p[8];
     3079            uint8_t lo = p[9];
     3080
     3081            s->tmp_dvb_p_buf[s->tmp_dvb_p_len++] = hi;
     3082            s->tmp_dvb_p_buf[s->tmp_dvb_p_len++] = lo;
     3083
     3084            /* If it's type 0x02 it can be repeated according to rules
     3085             * detailed in the above comment.
     3086             */
     3087            if ((dvb_cc_type == 0x02) &&
     3088                ((s->tmp_dvb_p_len + 2) < DVB_CC_BUF_SIZE)) {
     3089                dvb_cc_type = p[10];
     3090                if ((dvb_cc_type == 0x04) && ((hi & 0x7f) < 32) &&
     3091                    ((s->tmp_dvb_p_len + 4) < DVB_CC_BUF_SIZE)) {
     3092                    s->tmp_dvb_p_buf[s->tmp_dvb_p_len++] = hi;
     3093                    s->tmp_dvb_p_buf[s->tmp_dvb_p_len++] = lo;
     3094                }
     3095            } else if ((s->tmp_dvb_p_len + 4) < DVB_CC_BUF_SIZE) {
     3096                s->tmp_dvb_p_buf[s->tmp_dvb_p_len++] = p[10];
     3097                s->tmp_dvb_p_buf[s->tmp_dvb_p_len++] = p[11];
     3098                p += 2;
     3099                len -= 2;
     3100            }
     3101
     3102            p += 11;
     3103            len -= 11;
     3104        }
    30173105    }
    30183106}
    30193107
  • libs/libavcodec/avcodec.h

     
    667667    uint8_t atsc_cc_buf[1024];\
    668668    int atsc_cc_len;\
    669669\
     670    /** DVB CC data\
     671     * - encoding: unused\
     672     * - decoding: set by lavc\
     673     */\
     674    uint8_t dvb_cc_data[1024];\
     675    int dvb_cc_len;\
     676\
    670677
    671678#define FF_QSCALE_TYPE_MPEG1 0
    672679#define FF_QSCALE_TYPE_MPEG2 1