Statistics
| Branch: | Revision:

ffmpeg / libavformat / dv.c @ 0a5790d1

History | View | Annotate | Download (13.7 KB)

1 115329f1 Diego Biurrun
/*
2
 * General DV muxer/demuxer
3 064cf251 Diego Biurrun
 * Copyright (c) 2003 Roman Shaposhnik
4 7458ccbb Roman Shaposhnik
 *
5
 * Many thanks to Dan Dennedy <dan@dennedy.org> for providing wealth
6
 * of DV technical info.
7
 *
8 f20dca40 Fabrice Bellard
 * Raw DV format
9
 * Copyright (c) 2002 Fabrice Bellard.
10
 *
11 0b297700 Daniel Maas
 * 50 Mbps (DVCPRO50) support
12
 * Copyright (c) 2006 Daniel Maas <dmaas@maasdigital.com>
13
 *
14 b78e7197 Diego Biurrun
 * This file is part of FFmpeg.
15
 *
16
 * FFmpeg is free software; you can redistribute it and/or
17 f20dca40 Fabrice Bellard
 * modify it under the terms of the GNU Lesser General Public
18
 * License as published by the Free Software Foundation; either
19 b78e7197 Diego Biurrun
 * version 2.1 of the License, or (at your option) any later version.
20 f20dca40 Fabrice Bellard
 *
21 b78e7197 Diego Biurrun
 * FFmpeg is distributed in the hope that it will be useful,
22 f20dca40 Fabrice Bellard
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24
 * Lesser General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU Lesser General Public
27 b78e7197 Diego Biurrun
 * License along with FFmpeg; if not, write to the Free Software
28 5509bffa Diego Biurrun
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 f20dca40 Fabrice Bellard
 */
30 7458ccbb Roman Shaposhnik
#include <time.h>
31 f20dca40 Fabrice Bellard
#include "avformat.h"
32 7458ccbb Roman Shaposhnik
#include "dvdata.h"
33 ddaae6a9 Roman Shaposhnik
#include "dv.h"
34
35
struct DVDemuxContext {
36 0b297700 Daniel Maas
    const DVprofile*  sys;    /* Current DV profile. E.g.: 525/60, 625/50 */
37 ddaae6a9 Roman Shaposhnik
    AVFormatContext* fctx;
38
    AVStream*        vst;
39 115329f1 Diego Biurrun
    AVStream*        ast[2];
40 ddaae6a9 Roman Shaposhnik
    AVPacket         audio_pkt[2];
41 664f5836 Roman Shaposhnik
    uint8_t          audio_buf[2][8192];
42 ddaae6a9 Roman Shaposhnik
    int              ach;
43 8066e59f Roman Shaposhnik
    int              frames;
44
    uint64_t         abytes;
45 ddaae6a9 Roman Shaposhnik
};
46 f20dca40 Fabrice Bellard
47 7458ccbb Roman Shaposhnik
static inline uint16_t dv_audio_12to16(uint16_t sample)
48
{
49
    uint16_t shift, result;
50 115329f1 Diego Biurrun
51 7458ccbb Roman Shaposhnik
    sample = (sample < 0x800) ? sample : sample | 0xf000;
52
    shift = (sample & 0xf00) >> 8;
53
54
    if (shift < 0x2 || shift > 0xd) {
55 bb270c08 Diego Biurrun
        result = sample;
56 7458ccbb Roman Shaposhnik
    } else if (shift < 0x8) {
57
        shift--;
58 bb270c08 Diego Biurrun
        result = (sample - (256 * shift)) << shift;
59 7458ccbb Roman Shaposhnik
    } else {
60 bb270c08 Diego Biurrun
        shift = 0xe - shift;
61
        result = ((sample + ((256 * shift) + 1)) << shift) - 1;
62 7458ccbb Roman Shaposhnik
    }
63
64
    return result;
65
}
66
67 115329f1 Diego Biurrun
/*
68 7458ccbb Roman Shaposhnik
 * This is the dumbest implementation of all -- it simply looks at
69
 * a fixed offset and if pack isn't there -- fails. We might want
70
 * to have a fallback mechanism for complete search of missing packs.
71
 */
72
static const uint8_t* dv_extract_pack(uint8_t* frame, enum dv_pack_type t)
73
{
74
    int offs;
75 115329f1 Diego Biurrun
76 7458ccbb Roman Shaposhnik
    switch (t) {
77
    case dv_audio_source:
78
          offs = (80*6 + 80*16*3 + 3);
79 bb270c08 Diego Biurrun
          break;
80 7458ccbb Roman Shaposhnik
    case dv_audio_control:
81
          offs = (80*6 + 80*16*4 + 3);
82 bb270c08 Diego Biurrun
          break;
83 7458ccbb Roman Shaposhnik
    case dv_video_control:
84
          offs = (80*5 + 48 + 5);
85
          break;
86
    default:
87
          return NULL;
88 115329f1 Diego Biurrun
    }
89 7458ccbb Roman Shaposhnik
90
    return (frame[offs] == t ? &frame[offs] : NULL);
91
}
92
93 115329f1 Diego Biurrun
/*
94 7458ccbb Roman Shaposhnik
 * There's a couple of assumptions being made here:
95
 * 1. By default we silence erroneous (0x8000/16bit 0x800/12bit) audio samples.
96
 *    We can pass them upwards when ffmpeg will be ready to deal with them.
97
 * 2. We don't do software emphasis.
98
 * 3. Audio is always returned as 16bit linear samples: 12bit nonlinear samples
99
 *    are converted into 16bit linear ones.
100
 */
101 0b297700 Daniel Maas
static int dv_extract_audio(uint8_t* frame, uint8_t* pcm, uint8_t* pcm2,
102
                            const DVprofile *sys)
103 7458ccbb Roman Shaposhnik
{
104 0b297700 Daniel Maas
    int size, chan, i, j, d, of, smpls, freq, quant, half_ch;
105 7458ccbb Roman Shaposhnik
    uint16_t lc, rc;
106
    const uint8_t* as_pack;
107 115329f1 Diego Biurrun
108 7458ccbb Roman Shaposhnik
    as_pack = dv_extract_pack(frame, dv_audio_source);
109
    if (!as_pack)    /* No audio ? */
110 bb270c08 Diego Biurrun
        return 0;
111 115329f1 Diego Biurrun
112 7458ccbb Roman Shaposhnik
    smpls = as_pack[1] & 0x3f; /* samples in this frame - min. samples */
113
    freq = (as_pack[4] >> 3) & 0x07; /* 0 - 48KHz, 1 - 44,1kHz, 2 - 32 kHz */
114
    quant = as_pack[4] & 0x07; /* 0 - 16bit linear, 1 - 12bit nonlinear */
115 115329f1 Diego Biurrun
116 7458ccbb Roman Shaposhnik
    if (quant > 1)
117 bb270c08 Diego Biurrun
        return -1; /* Unsupported quantization */
118 7458ccbb Roman Shaposhnik
119
    size = (sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */
120 ddaae6a9 Roman Shaposhnik
    half_ch = sys->difseg_size/2;
121 7458ccbb Roman Shaposhnik
122 0b297700 Daniel Maas
    /* for each DIF channel */
123
    for (chan = 0; chan < sys->n_difchan; chan++) {
124
        /* for each DIF segment */
125
        for (i = 0; i < sys->difseg_size; i++) {
126
            frame += 6 * 80; /* skip DIF segment header */
127
            if (quant == 1 && i == half_ch) {
128
                /* next stereo channel (12bit mode only) */
129
                if (!pcm2)
130
                    break;
131
                else
132
                    pcm = pcm2;
133
            }
134 bb270c08 Diego Biurrun
135 0b297700 Daniel Maas
            /* for each AV sequence */
136
            for (j = 0; j < 9; j++) {
137
                for (d = 8; d < 80; d += 2) {
138
                    if (quant == 0) {  /* 16bit quantization */
139
                        of = sys->audio_shuffle[i][j] + (d - 8)/2 * sys->audio_stride;
140
                        if (of*2 >= size)
141
                            continue;
142
143
                        pcm[of*2] = frame[d+1]; // FIXME: may be we have to admit
144
                        pcm[of*2+1] = frame[d]; //        that DV is a big endian PCM
145
                        if (pcm[of*2+1] == 0x80 && pcm[of*2] == 0x00)
146
                            pcm[of*2+1] = 0;
147
                    } else {           /* 12bit quantization */
148
                        lc = ((uint16_t)frame[d] << 4) |
149
                             ((uint16_t)frame[d+2] >> 4);
150
                        rc = ((uint16_t)frame[d+1] << 4) |
151
                             ((uint16_t)frame[d+2] & 0x0f);
152
                        lc = (lc == 0x800 ? 0 : dv_audio_12to16(lc));
153
                        rc = (rc == 0x800 ? 0 : dv_audio_12to16(rc));
154
155
                        of = sys->audio_shuffle[i%half_ch][j] + (d - 8)/3 * sys->audio_stride;
156
                        if (of*2 >= size)
157
                            continue;
158
159
                        pcm[of*2] = lc & 0xff; // FIXME: may be we have to admit
160
                        pcm[of*2+1] = lc >> 8; //        that DV is a big endian PCM
161
                        of = sys->audio_shuffle[i%half_ch+half_ch][j] +
162
                            (d - 8)/3 * sys->audio_stride;
163
                        pcm[of*2] = rc & 0xff; // FIXME: may be we have to admit
164
                        pcm[of*2+1] = rc >> 8; //        that DV is a big endian PCM
165
                        ++d;
166
                    }
167
                }
168
169
                frame += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */
170
            }
171 7458ccbb Roman Shaposhnik
        }
172 0b297700 Daniel Maas
173
        /* next stereo channel (50Mbps only) */
174
        if(!pcm2)
175
            break;
176
        pcm = pcm2;
177 7458ccbb Roman Shaposhnik
    }
178
179
    return size;
180
}
181
182 ddaae6a9 Roman Shaposhnik
static int dv_extract_audio_info(DVDemuxContext* c, uint8_t* frame)
183 7458ccbb Roman Shaposhnik
{
184
    const uint8_t* as_pack;
185 0b297700 Daniel Maas
    int freq, stype, smpls, quant, i, ach;
186 7458ccbb Roman Shaposhnik
187
    as_pack = dv_extract_pack(frame, dv_audio_source);
188 0b297700 Daniel Maas
    if (!as_pack || !c->sys) {    /* No audio ? */
189 ddaae6a9 Roman Shaposhnik
        c->ach = 0;
190 bb270c08 Diego Biurrun
        return 0;
191 ddaae6a9 Roman Shaposhnik
    }
192 115329f1 Diego Biurrun
193 7458ccbb Roman Shaposhnik
    smpls = as_pack[1] & 0x3f; /* samples in this frame - min. samples */
194
    freq = (as_pack[4] >> 3) & 0x07; /* 0 - 48KHz, 1 - 44,1kHz, 2 - 32 kHz */
195 0b297700 Daniel Maas
    stype = (as_pack[3] & 0x1f); /* 0 - 2CH, 2 - 4CH */
196 ddaae6a9 Roman Shaposhnik
    quant = as_pack[4] & 0x07; /* 0 - 16bit linear, 1 - 12bit nonlinear */
197 0b297700 Daniel Maas
198
    /* note: ach counts PAIRS of channels (i.e. stereo channels) */
199
    ach = (stype == 2 || (quant && (freq == 2))) ? 2 : 1;
200 50883632 Roman Shaposhnik
201
    /* Dynamic handling of the audio streams in DV */
202
    for (i=0; i<ach; i++) {
203
       if (!c->ast[i]) {
204
           c->ast[i] = av_new_stream(c->fctx, 0);
205 bb270c08 Diego Biurrun
           if (!c->ast[i])
206
               break;
207
           av_set_pts_info(c->ast[i], 64, 1, 30000);
208
           c->ast[i]->codec->codec_type = CODEC_TYPE_AUDIO;
209
           c->ast[i]->codec->codec_id = CODEC_ID_PCM_S16LE;
210 664f5836 Roman Shaposhnik
211
           av_init_packet(&c->audio_pkt[i]);
212
           c->audio_pkt[i].size     = 0;
213
           c->audio_pkt[i].data     = c->audio_buf[i];
214
           c->audio_pkt[i].stream_index = c->ast[i]->index;
215
           c->audio_pkt[i].flags |= PKT_FLAG_KEY;
216 50883632 Roman Shaposhnik
       }
217 01f4895c Michael Niedermayer
       c->ast[i]->codec->sample_rate = dv_audio_frequency[freq];
218
       c->ast[i]->codec->channels = 2;
219
       c->ast[i]->codec->bit_rate = 2 * dv_audio_frequency[freq] * 16;
220 50883632 Roman Shaposhnik
       c->ast[i]->start_time = 0;
221 ddaae6a9 Roman Shaposhnik
    }
222 50883632 Roman Shaposhnik
    c->ach = i;
223 115329f1 Diego Biurrun
224 0b297700 Daniel Maas
    return (c->sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */;
225 7458ccbb Roman Shaposhnik
}
226
227 ddaae6a9 Roman Shaposhnik
static int dv_extract_video_info(DVDemuxContext *c, uint8_t* frame)
228 7458ccbb Roman Shaposhnik
{
229
    const uint8_t* vsc_pack;
230 ddaae6a9 Roman Shaposhnik
    AVCodecContext* avctx;
231
    int apt, is16_9;
232 7458ccbb Roman Shaposhnik
    int size = 0;
233 115329f1 Diego Biurrun
234 0b297700 Daniel Maas
    if (c->sys) {
235 01f4895c Michael Niedermayer
        avctx = c->vst->codec;
236 115329f1 Diego Biurrun
237 0b297700 Daniel Maas
        av_set_pts_info(c->vst, 64, c->sys->frame_rate_base, c->sys->frame_rate);
238
        avctx->time_base= (AVRational){c->sys->frame_rate_base, c->sys->frame_rate};
239 4325ffd0 Michael Niedermayer
        if(!avctx->width){
240 0b297700 Daniel Maas
            avctx->width = c->sys->width;
241
            avctx->height = c->sys->height;
242 4325ffd0 Michael Niedermayer
        }
243 0b297700 Daniel Maas
        avctx->pix_fmt = c->sys->pix_fmt;
244 115329f1 Diego Biurrun
245 bb270c08 Diego Biurrun
        /* finding out SAR is a little bit messy */
246
        vsc_pack = dv_extract_pack(frame, dv_video_control);
247 ddaae6a9 Roman Shaposhnik
        apt = frame[4] & 0x07;
248 bb270c08 Diego Biurrun
        is16_9 = (vsc_pack && ((vsc_pack[2] & 0x07) == 0x02 ||
249
                               (!apt && (vsc_pack[2] & 0x07) == 0x07)));
250 0b297700 Daniel Maas
        avctx->sample_aspect_ratio = c->sys->sar[is16_9];
251
        avctx->bit_rate = av_rescale(c->sys->frame_size * 8,
252
                                     c->sys->frame_rate,
253
                                     c->sys->frame_rate_base);
254
        size = c->sys->frame_size;
255 7458ccbb Roman Shaposhnik
    }
256
    return size;
257
}
258
259 115329f1 Diego Biurrun
/*
260 d4fc91b4 Panagiotis Issaris
 * The following 3 functions constitute our interface to the world
261 7458ccbb Roman Shaposhnik
 */
262
263 ddaae6a9 Roman Shaposhnik
DVDemuxContext* dv_init_demux(AVFormatContext *s)
264 7458ccbb Roman Shaposhnik
{
265
    DVDemuxContext *c;
266
267
    c = av_mallocz(sizeof(DVDemuxContext));
268
    if (!c)
269
        return NULL;
270
271 ddaae6a9 Roman Shaposhnik
    c->vst = av_new_stream(s, 0);
272 50883632 Roman Shaposhnik
    if (!c->vst) {
273 115329f1 Diego Biurrun
        av_free(c);
274 50883632 Roman Shaposhnik
        return NULL;
275
    }
276 9ee91c2f Michael Niedermayer
277 0b297700 Daniel Maas
    c->sys = NULL;
278 ddaae6a9 Roman Shaposhnik
    c->fctx = s;
279 50883632 Roman Shaposhnik
    c->ast[0] = c->ast[1] = NULL;
280 ddaae6a9 Roman Shaposhnik
    c->ach = 0;
281 8066e59f Roman Shaposhnik
    c->frames = 0;
282
    c->abytes = 0;
283 664f5836 Roman Shaposhnik
284 01f4895c Michael Niedermayer
    c->vst->codec->codec_type = CODEC_TYPE_VIDEO;
285
    c->vst->codec->codec_id = CODEC_ID_DVVIDEO;
286
    c->vst->codec->bit_rate = 25000000;
287 c4e55470 Roman Shaposhnik
    c->vst->start_time = 0;
288 115329f1 Diego Biurrun
289 7458ccbb Roman Shaposhnik
    return c;
290 f20dca40 Fabrice Bellard
}
291
292 7458ccbb Roman Shaposhnik
int dv_get_packet(DVDemuxContext *c, AVPacket *pkt)
293 f20dca40 Fabrice Bellard
{
294 7458ccbb Roman Shaposhnik
    int size = -1;
295 ddaae6a9 Roman Shaposhnik
    int i;
296
297
    for (i=0; i<c->ach; i++) {
298
       if (c->ast[i] && c->audio_pkt[i].size) {
299
           *pkt = c->audio_pkt[i];
300 bb270c08 Diego Biurrun
           c->audio_pkt[i].size = 0;
301
           size = pkt->size;
302
           break;
303 ddaae6a9 Roman Shaposhnik
       }
304 425ed6e2 Fabrice Bellard
    }
305 7458ccbb Roman Shaposhnik
306
    return size;
307
}
308
309 115329f1 Diego Biurrun
int dv_produce_packet(DVDemuxContext *c, AVPacket *pkt,
310 7458ccbb Roman Shaposhnik
                      uint8_t* buf, int buf_size)
311
{
312 ddaae6a9 Roman Shaposhnik
    int size, i;
313 115329f1 Diego Biurrun
314 c4e7baa8 Roman Shaposhnik
    if (buf_size < DV_PROFILE_BYTES ||
315
        !(c->sys = dv_frame_profile(buf)) ||
316
        buf_size < c->sys->frame_size) {
317
          return -1;   /* Broken frame, or not enough data */
318
    }
319 7458ccbb Roman Shaposhnik
320
    /* Queueing audio packet */
321
    /* FIXME: in case of no audio/bad audio we have to do something */
322 ddaae6a9 Roman Shaposhnik
    size = dv_extract_audio_info(c, buf);
323
    for (i=0; i<c->ach; i++) {
324 664f5836 Roman Shaposhnik
       c->audio_pkt[i].size = size;
325 01f4895c Michael Niedermayer
       c->audio_pkt[i].pts  = c->abytes * 30000*8 / c->ast[i]->codec->bit_rate;
326 ddaae6a9 Roman Shaposhnik
    }
327 0b297700 Daniel Maas
    dv_extract_audio(buf, c->audio_buf[0], c->audio_buf[1], c->sys);
328 8066e59f Roman Shaposhnik
    c->abytes += size;
329 115329f1 Diego Biurrun
330 7458ccbb Roman Shaposhnik
    /* Now it's time to return video packet */
331 ddaae6a9 Roman Shaposhnik
    size = dv_extract_video_info(c, buf);
332 ec820113 Fabrice Bellard
    av_init_packet(pkt);
333 7458ccbb Roman Shaposhnik
    pkt->data     = buf;
334 115329f1 Diego Biurrun
    pkt->size     = size;
335 e738cee9 Roman Shaposhnik
    pkt->flags   |= PKT_FLAG_KEY;
336 7458ccbb Roman Shaposhnik
    pkt->stream_index = c->vst->id;
337 eb1bde3e Michael Niedermayer
    pkt->pts      = c->frames;
338 115329f1 Diego Biurrun
339 8066e59f Roman Shaposhnik
    c->frames++;
340 ddaae6a9 Roman Shaposhnik
341 7458ccbb Roman Shaposhnik
    return size;
342
}
343 115329f1 Diego Biurrun
344 83582de4 Michael Niedermayer
static int64_t dv_frame_offset(AVFormatContext *s, DVDemuxContext *c,
345
                              int64_t timestamp, int flags)
346 8066e59f Roman Shaposhnik
{
347 0bf4e2b8 Nathan Kurz
    // FIXME: sys may be wrong if last dv_read_packet() failed (buffer is junk)
348 01f4895c Michael Niedermayer
    const DVprofile* sys = dv_codec_profile(c->vst->codec);
349 eb1bde3e Michael Niedermayer
    int64_t offset;
350 a965c478 Aurelien Jacobs
    int64_t size = url_fsize(&s->pb);
351 83582de4 Michael Niedermayer
    int64_t max_offset = ((size-1) / sys->frame_size) * sys->frame_size;
352 0bf4e2b8 Nathan Kurz
353 eb1bde3e Michael Niedermayer
    offset = sys->frame_size * timestamp;
354 115329f1 Diego Biurrun
355 83582de4 Michael Niedermayer
    if (offset > max_offset) offset = max_offset;
356
    else if (offset < 0) offset = 0;
357 8066e59f Roman Shaposhnik
358 0bf4e2b8 Nathan Kurz
    return offset;
359 8066e59f Roman Shaposhnik
}
360
361 6eb2de74 Roman Shaposhnik
void dv_offset_reset(DVDemuxContext *c, int64_t frame_offset)
362 664f5836 Roman Shaposhnik
{
363 6eb2de74 Roman Shaposhnik
    c->frames= frame_offset;
364
    if (c->ach)
365
        c->abytes= av_rescale(c->frames,
366
                          c->ast[0]->codec->bit_rate * (int64_t)c->sys->frame_rate_base,
367
                          8*c->sys->frame_rate);
368 664f5836 Roman Shaposhnik
    c->audio_pkt[0].size = c->audio_pkt[1].size = 0;
369
}
370
371 7458ccbb Roman Shaposhnik
/************************************************************
372
 * Implementation of the easiest DV storage of all -- raw DV.
373
 ************************************************************/
374 115329f1 Diego Biurrun
375 7458ccbb Roman Shaposhnik
typedef struct RawDVContext {
376 ddaae6a9 Roman Shaposhnik
    DVDemuxContext* dv_demux;
377 0b297700 Daniel Maas
    uint8_t         buf[DV_MAX_FRAME_SIZE];
378 7458ccbb Roman Shaposhnik
} RawDVContext;
379
380
static int dv_read_header(AVFormatContext *s,
381
                          AVFormatParameters *ap)
382
{
383
    RawDVContext *c = s->priv_data;
384 0b297700 Daniel Maas
385 ddaae6a9 Roman Shaposhnik
    c->dv_demux = dv_init_demux(s);
386 c4e55470 Roman Shaposhnik
    if (!c->dv_demux)
387
        return -1;
388 115329f1 Diego Biurrun
389 0b297700 Daniel Maas
    if (get_buffer(&s->pb, c->buf, DV_PROFILE_BYTES) <= 0 ||
390
        url_fseek(&s->pb, -DV_PROFILE_BYTES, SEEK_CUR) < 0)
391 6f3e0b21 Panagiotis Issaris
        return AVERROR(EIO);
392 c4e55470 Roman Shaposhnik
393 0b297700 Daniel Maas
    c->dv_demux->sys = dv_frame_profile(c->buf);
394
    s->bit_rate = av_rescale(c->dv_demux->sys->frame_size * 8,
395
                             c->dv_demux->sys->frame_rate,
396
                             c->dv_demux->sys->frame_rate_base);
397 115329f1 Diego Biurrun
398 c4e55470 Roman Shaposhnik
    return 0;
399 7458ccbb Roman Shaposhnik
}
400
401
402
static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
403
{
404
    int size;
405 115329f1 Diego Biurrun
    RawDVContext *c = s->priv_data;
406
407 7458ccbb Roman Shaposhnik
    size = dv_get_packet(c->dv_demux, pkt);
408 115329f1 Diego Biurrun
409 7458ccbb Roman Shaposhnik
    if (size < 0) {
410 0b297700 Daniel Maas
        size = c->dv_demux->sys->frame_size;
411
        if (get_buffer(&s->pb, c->buf, size) <= 0)
412 6f3e0b21 Panagiotis Issaris
            return AVERROR(EIO);
413 7458ccbb Roman Shaposhnik
414 bb270c08 Diego Biurrun
        size = dv_produce_packet(c->dv_demux, pkt, c->buf, size);
415 115329f1 Diego Biurrun
    }
416
417 7458ccbb Roman Shaposhnik
    return size;
418 f20dca40 Fabrice Bellard
}
419
420 115329f1 Diego Biurrun
static int dv_read_seek(AVFormatContext *s, int stream_index,
421 83582de4 Michael Niedermayer
                       int64_t timestamp, int flags)
422 8066e59f Roman Shaposhnik
{
423 83582de4 Michael Niedermayer
    RawDVContext *r = s->priv_data;
424
    DVDemuxContext *c = r->dv_demux;
425
    int64_t offset= dv_frame_offset(s, c, timestamp, flags);
426
427 6eb2de74 Roman Shaposhnik
    dv_offset_reset(c, offset / c->sys->frame_size);
428 115329f1 Diego Biurrun
429 05ce0f11 Maksym Veremeyenko
    offset = url_fseek(&s->pb, offset, SEEK_SET);
430
    return (offset < 0)?offset:0;
431 8066e59f Roman Shaposhnik
}
432
433 c18a2692 Zdenek Kabelac
static int dv_read_close(AVFormatContext *s)
434 f20dca40 Fabrice Bellard
{
435 7458ccbb Roman Shaposhnik
    RawDVContext *c = s->priv_data;
436
    av_free(c->dv_demux);
437 f20dca40 Fabrice Bellard
    return 0;
438
}
439
440 ff70e601 Måns Rullgård
#ifdef CONFIG_DV_DEMUXER
441
AVInputFormat dv_demuxer = {
442 118e91f3 Roman Shaposhnik
    "dv",
443
    "DV video format",
444 7458ccbb Roman Shaposhnik
    sizeof(RawDVContext),
445 118e91f3 Roman Shaposhnik
    NULL,
446
    dv_read_header,
447
    dv_read_packet,
448
    dv_read_close,
449 8066e59f Roman Shaposhnik
    dv_read_seek,
450 490c735d Roman Shaposhnik
    .extensions = "dv,dif",
451 118e91f3 Roman Shaposhnik
};
452 ff70e601 Måns Rullgård
#endif