| 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 | } |