Revision 5f1ac36d

View differences:

Changelog
16 16
- Cook multichannel decoding support
17 17
- introduced avlanguage helpers in libavformat
18 18
- 8088flex TMV demuxer and decoder
19
- per-stream language-tags extraction in asfdec
19 20

  
20 21

  
21 22
version 0.5:
libavformat/Makefile
18 18
OBJS-$(CONFIG_AMR_MUXER)                 += amr.o
19 19
OBJS-$(CONFIG_APC_DEMUXER)               += apc.o
20 20
OBJS-$(CONFIG_APE_DEMUXER)               += ape.o
21
OBJS-$(CONFIG_ASF_DEMUXER)               += asfdec.o asf.o asfcrypt.o riff.o
21
OBJS-$(CONFIG_ASF_DEMUXER)               += asfdec.o asf.o asfcrypt.o riff.o avlanguage.o
22 22
OBJS-$(CONFIG_ASF_MUXER)                 += asfenc.o asf.o riff.o
23 23
OBJS-$(CONFIG_ASF_STREAM_MUXER)          += asfenc.o asf.o riff.o
24 24
OBJS-$(CONFIG_ASS_DEMUXER)               += assdec.o
libavformat/asf.c
112 112
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
113 113
};
114 114

  
115
const ff_asf_guid ff_asf_language_guid = {
116
    0xa9, 0x46, 0x43, 0x7c, 0xe0, 0xef, 0xfc, 0x4b, 0xb2, 0x29, 0x39, 0x3e, 0xde, 0x41, 0x5c, 0x85
117
};
115 118

  
116 119
const AVMetadataConv ff_asf_metadata_conv[] = {
117 120
    { "AlbumArtist", "artist"    },
libavformat/asf.h
42 42

  
43 43
    int64_t packet_pos;
44 44

  
45
    uint16_t stream_language_index;
46

  
45 47
} ASFStream;
46 48

  
47 49
typedef uint8_t ff_asf_guid[16];
......
85 87
    int asfid2avid[128];                 ///< conversion table from asf ID 2 AVStream ID
86 88
    ASFStream streams[128];              ///< it's max number and it's not that big
87 89
    uint32_t stream_bitrates[128];       ///< max number of streams, bitrate for each (for streaming)
90
    char stream_languages[128][6];       ///< max number of streams, language for each (RFC1766, e.g. en-US)
88 91
    /* non streamed additonnal info */
89 92
    uint64_t nb_packets;                 ///< how many packets are there in the file, invalid if broadcasting
90 93
    int64_t duration;                    ///< in 100ns units
......
157 160
extern const ff_asf_guid ff_asf_ext_stream_audio_stream;
158 161
extern const ff_asf_guid ff_asf_metadata_header;
159 162
extern const ff_asf_guid ff_asf_my_guid;
163
extern const ff_asf_guid ff_asf_language_guid;
160 164

  
161 165
extern const AVMetadataConv ff_asf_metadata_conv[];
162 166

  
libavformat/asfdec.c
20 20
 */
21 21

  
22 22
#include "libavutil/common.h"
23
#include "libavutil/avstring.h"
23 24
#include "libavcodec/mpegaudio.h"
24 25
#include "avformat.h"
25 26
#include "riff.h"
26 27
#include "asf.h"
27 28
#include "asfcrypt.h"
29
#include "avlanguage.h"
28 30

  
29 31
void ff_mms_set_stream_selection(URLContext *h, AVFormatContext *format);
30 32

  
......
76 78
    else PRINT_IF_GUID(g, ff_asf_ext_stream_audio_stream);
77 79
    else PRINT_IF_GUID(g, ff_asf_metadata_header);
78 80
    else PRINT_IF_GUID(g, stream_bitrate_guid);
81
    else PRINT_IF_GUID(g, ff_asf_language_guid);
79 82
    else
80 83
        dprintf(NULL, "(GUID: unknown) ");
81 84
    for(i=0;i<16;i++)
......
238 241
            st->priv_data = asf_st;
239 242
            start_time = asf->hdr.preroll;
240 243

  
244
            asf_st->stream_language_index = 128; // invalid stream index means no language info
245

  
241 246
            if(!(asf->hdr.flags & 0x01)) { // if we aren't streaming...
242 247
                st->duration = asf->hdr.send_time /
243 248
                    (10000000 / 1000) - start_time;
......
403 408
//                av_log(s, AV_LOG_ERROR, "flags: 0x%x stream id %d, bitrate %d\n", flags, stream_id, bitrate);
404 409
                asf->stream_bitrates[stream_id]= bitrate;
405 410
            }
411
        } else if (!guidcmp(&g, &ff_asf_language_guid)) {
412
            int j;
413
            int stream_count = get_le16(pb);
414
            for(j = 0; j < stream_count; j++) {
415
                char lang[6];
416
                unsigned int lang_len = get_byte(pb);
417
                get_str16_nolen(pb, lang_len, lang, sizeof(lang));
418
                if (j < 128)
419
                    av_strlcpy(asf->stream_languages[j], lang, sizeof(*asf->stream_languages));
420
            }
406 421
        } else if (!guidcmp(&g, &ff_asf_extended_content_header)) {
407 422
            int desc_count, i;
408 423

  
......
443 458
        } else if (!guidcmp(&g, &ff_asf_ext_stream_header)) {
444 459
            int ext_len, payload_ext_ct, stream_ct;
445 460
            uint32_t ext_d, leak_rate, stream_num;
461
            unsigned int stream_languageid_index;
446 462

  
447 463
            get_le64(pb); // starttime
448 464
            get_le64(pb); // endtime
......
455 471
            get_le32(pb); // max-object-size
456 472
            get_le32(pb); // flags (reliable,seekable,no_cleanpoints?,resend-live-cleanpoints, rest of bits reserved)
457 473
            stream_num = get_le16(pb); // stream-num
458
            get_le16(pb); // stream-language-id-index
474

  
475
            stream_languageid_index = get_le16(pb); // stream-language-id-index
476
            if (stream_num < 128)
477
                asf->streams[stream_num].stream_language_index = stream_languageid_index;
478

  
459 479
            get_le64(pb); // avg frametime in 100ns units
460 480
            stream_ct = get_le16(pb); //stream-name-count
461 481
            payload_ext_ct = get_le16(pb); //payload-extension-system-count
......
535 555
                          &st->sample_aspect_ratio.den,
536 556
                          dar[i].num, dar[i].den, INT_MAX);
537 557
//av_log(s, AV_LOG_ERROR, "dar %d:%d sar=%d:%d\n", dar[i].num, dar[i].den, st->sample_aspect_ratio.num, st->sample_aspect_ratio.den);
558

  
559
            // copy and convert language codes to the frontend
560
            if (asf->streams[i].stream_language_index < 128) {
561
                const char *rfc1766 = asf->stream_languages[asf->streams[i].stream_language_index];
562
                if (rfc1766 && strlen(rfc1766) > 1) {
563
                    const char primary_tag[3] = { rfc1766[0], rfc1766[1], '\0' }; // ignore country code if any
564
                    const char *iso6392 = av_convert_lang_to(primary_tag, AV_LANG_ISO639_2_BIBL);
565
                    if (iso6392)
566
                        av_metadata_set(&st->metadata, "language", iso6392);
567
                }
568
            }
538 569
        }
539 570
    }
540 571

  

Also available in: Unified diff