~siretart/libav/trusty

« back to all changes in this revision

Viewing changes to libavformat/gxf.c

  • Committer: Reinhard Tartler
  • Date: 2013-10-23 03:04:17 UTC
  • mfrom: (1.3.36 sid)
  • Revision ID: siretart@tauware.de-20131023030417-1o6mpkl1l0raifjt
mergeĀ fromĀ debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
20
 */
21
21
 
 
22
#include "libavutil/channel_layout.h"
22
23
#include "libavutil/common.h"
23
24
#include "avformat.h"
24
25
#include "internal.h"
25
26
#include "gxf.h"
 
27
#include "libavcodec/mpeg12data.h"
26
28
 
27
29
struct gxf_stream_info {
28
30
    int64_t first_field;
89
91
        case 3:
90
92
        case 4:
91
93
            st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
92
 
            st->codec->codec_id = CODEC_ID_MJPEG;
 
94
            st->codec->codec_id = AV_CODEC_ID_MJPEG;
93
95
            break;
94
96
        case 13:
95
97
        case 15:
96
98
            st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
97
 
            st->codec->codec_id = CODEC_ID_DVVIDEO;
 
99
            st->codec->codec_id = AV_CODEC_ID_DVVIDEO;
98
100
            break;
99
101
        case 14:
100
102
        case 16:
101
103
            st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
102
 
            st->codec->codec_id = CODEC_ID_DVVIDEO;
 
104
            st->codec->codec_id = AV_CODEC_ID_DVVIDEO;
103
105
            break;
104
106
        case 11:
105
107
        case 12:
106
108
        case 20:
107
109
            st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
108
 
            st->codec->codec_id = CODEC_ID_MPEG2VIDEO;
 
110
            st->codec->codec_id = AV_CODEC_ID_MPEG2VIDEO;
109
111
            st->need_parsing = AVSTREAM_PARSE_HEADERS; //get keyframe flag etc.
110
112
            break;
111
113
        case 22:
112
114
        case 23:
113
115
            st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
114
 
            st->codec->codec_id = CODEC_ID_MPEG1VIDEO;
 
116
            st->codec->codec_id = AV_CODEC_ID_MPEG1VIDEO;
115
117
            st->need_parsing = AVSTREAM_PARSE_HEADERS; //get keyframe flag etc.
116
118
            break;
117
119
        case 9:
118
120
            st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
119
 
            st->codec->codec_id = CODEC_ID_PCM_S24LE;
 
121
            st->codec->codec_id = AV_CODEC_ID_PCM_S24LE;
120
122
            st->codec->channels = 1;
 
123
            st->codec->channel_layout = AV_CH_LAYOUT_MONO;
121
124
            st->codec->sample_rate = 48000;
122
125
            st->codec->bit_rate = 3 * 1 * 48000 * 8;
123
126
            st->codec->block_align = 3 * 1;
125
128
            break;
126
129
        case 10:
127
130
            st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
128
 
            st->codec->codec_id = CODEC_ID_PCM_S16LE;
 
131
            st->codec->codec_id = AV_CODEC_ID_PCM_S16LE;
129
132
            st->codec->channels = 1;
 
133
            st->codec->channel_layout = AV_CH_LAYOUT_MONO;
130
134
            st->codec->sample_rate = 48000;
131
135
            st->codec->bit_rate = 2 * 1 * 48000 * 8;
132
136
            st->codec->block_align = 2 * 1;
134
138
            break;
135
139
        case 17:
136
140
            st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
137
 
            st->codec->codec_id = CODEC_ID_AC3;
 
141
            st->codec->codec_id = AV_CODEC_ID_AC3;
138
142
            st->codec->channels = 2;
 
143
            st->codec->channel_layout = AV_CH_LAYOUT_STEREO;
139
144
            st->codec->sample_rate = 48000;
140
145
            break;
141
146
        // timecode tracks:
143
148
        case 8:
144
149
        case 24:
145
150
            st->codec->codec_type = AVMEDIA_TYPE_DATA;
146
 
            st->codec->codec_id = CODEC_ID_NONE;
 
151
            st->codec->codec_id = AV_CODEC_ID_NONE;
147
152
            break;
148
153
        default:
149
154
            st->codec->codec_type = AVMEDIA_TYPE_UNKNOWN;
150
 
            st->codec->codec_id = CODEC_ID_NONE;
 
155
            st->codec->codec_id = AV_CODEC_ID_NONE;
151
156
            break;
152
157
    }
153
158
    return s->nb_streams - 1;
179
184
    }
180
185
}
181
186
 
 
187
static const AVRational frame_rate_tab[] = {
 
188
    {   60,    1},
 
189
    {60000, 1001},
 
190
    {   50,    1},
 
191
    {   30,    1},
 
192
    {30000, 1001},
 
193
    {   25,    1},
 
194
    {   24,    1},
 
195
    {24000, 1001},
 
196
    {    0,    0},
 
197
};
 
198
 
182
199
/**
183
200
 * @brief convert fps tag value to AVRational fps
184
201
 * @param fps fps value from tag
185
202
 * @return fps as AVRational, or 0 / 0 if unknown
186
203
 */
187
204
static AVRational fps_tag2avr(int32_t fps) {
188
 
    extern const AVRational avpriv_frame_rate_tab[];
189
205
    if (fps < 1 || fps > 9) fps = 9;
190
 
    return avpriv_frame_rate_tab[9 - fps]; // values have opposite order
 
206
    return frame_rate_tab[fps - 1];
191
207
}
192
208
 
193
209
/**
259
275
    avio_skip(pb, pkt_len);
260
276
}
261
277
 
262
 
static int gxf_header(AVFormatContext *s, AVFormatParameters *ap) {
 
278
static int gxf_header(AVFormatContext *s) {
263
279
    AVIOContext *pb = s->pb;
264
280
    GXFPktType pkt_type;
265
281
    int map_len;
459
475
        avio_rb32(pb); // "timeline" field number
460
476
        avio_r8(pb); // flags
461
477
        avio_r8(pb); // reserved
462
 
        if (st->codec->codec_id == CODEC_ID_PCM_S24LE ||
463
 
            st->codec->codec_id == CODEC_ID_PCM_S16LE) {
 
478
        if (st->codec->codec_id == AV_CODEC_ID_PCM_S24LE ||
 
479
            st->codec->codec_id == AV_CODEC_ID_PCM_S16LE) {
464
480
            int first = field_info >> 16;
465
481
            int last  = field_info & 0xffff; // last is exclusive
466
482
            int bps = av_get_bits_per_sample(st->codec->codec_id)>>3;
478
494
        pkt->dts = field_nr;
479
495
 
480
496
        //set duration manually for DV or else lavf misdetects the frame rate
481
 
        if (st->codec->codec_id == CODEC_ID_DVVIDEO)
 
497
        if (st->codec->codec_id == AV_CODEC_ID_DVVIDEO)
482
498
            pkt->duration = si->fields_per_frame;
483
499
 
484
500
        return ret;
525
541
 
526
542
AVInputFormat ff_gxf_demuxer = {
527
543
    .name           = "gxf",
528
 
    .long_name      = NULL_IF_CONFIG_SMALL("GXF format"),
 
544
    .long_name      = NULL_IF_CONFIG_SMALL("GXF (General eXchange Format)"),
529
545
    .priv_data_size = sizeof(struct gxf_stream_info),
530
546
    .read_probe     = gxf_probe,
531
547
    .read_header    = gxf_header,