Revision 435cebd0 libavformat/mpegtsenc.c

View differences:

libavformat/mpegtsenc.c
283 283
        /* write optional descriptors here */
284 284
        switch(st->codec->codec_type) {
285 285
        case AVMEDIA_TYPE_AUDIO:
286
            if (lang && strlen(lang->value) == 3) {
286
            if (lang) {
287
                char *p;
288
                char *next = lang->value;
289
                uint8_t *len_ptr;
290

  
287 291
                *q++ = 0x0a; /* ISO 639 language descriptor */
288
                *q++ = 4;
289
                *q++ = lang->value[0];
290
                *q++ = lang->value[1];
291
                *q++ = lang->value[2];
292
                len_ptr = q++;
293
                *len_ptr = 0;
294

  
295
                for (p = lang->value; next && *len_ptr < 255 / 4 * 4; p = next + 1) {
296
                    next = strchr(p, ',');
297
                    if (strlen(p) != 3 && (!next || next != p + 3))
298
                        continue; /* not a 3-letter code */
299

  
300
                    *q++ = *p++;
301
                    *q++ = *p++;
302
                    *q++ = *p++;
303

  
292 304
                if (st->disposition & AV_DISPOSITION_CLEAN_EFFECTS)
293 305
                    *q++ = 0x01;
294 306
                else if (st->disposition & AV_DISPOSITION_HEARING_IMPAIRED)
......
297 309
                    *q++ = 0x03;
298 310
                else
299 311
                    *q++ = 0; /* undefined type */
312

  
313
                    *len_ptr += 4;
314
                }
315

  
316
                if (*len_ptr == 0)
317
                    q -= 2; /* no language codes were written */
300 318
            }
301 319
            break;
302 320
        case AVMEDIA_TYPE_SUBTITLE:

Also available in: Unified diff