annotate avisynth.c @ 4441:0fd16041ac29 libavformat

fix timecode value
author bcoudurier
date Tue, 10 Feb 2009 22:59:13 +0000
parents b43c5c858f25
children 33a244b7ca65
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1283
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
1 /*
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
2 * AVISynth support for ffmpeg system
4253
b43c5c858f25 Restore mistakenly removed period after "DivX, Inc".
diego
parents: 4251
diff changeset
3 * Copyright (c) 2006 DivX, Inc.
1283
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
4 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1346
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1346
diff changeset
6 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1346
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
1283
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1346
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
1283
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1346
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
1283
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
15 * Lesser General Public License for more details.
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
16 *
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1346
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
1283
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
20 */
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
21
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
22 #include "avformat.h"
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
23 #include "riff.h"
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
24
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
25 #include <windows.h>
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
26 #include <vfw.h>
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
27
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
28 typedef struct {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
29 PAVISTREAM handle;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
30 AVISTREAMINFO info;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
31 DWORD read;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
32 LONG chunck_size;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
33 LONG chunck_samples;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
34 } AVISynthStream;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
35
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
36 typedef struct {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
37 PAVIFILE file;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
38 AVISynthStream *streams;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
39 int nb_streams;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
40 int next_stream;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
41 } AVISynthContext;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
42
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
43 static int avisynth_read_header(AVFormatContext *s, AVFormatParameters *ap)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
44 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
45 AVISynthContext *avs = s->priv_data;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
46 HRESULT res;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
47 AVIFILEINFO info;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
48 DWORD id;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
49 AVStream *st;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
50 AVISynthStream *stream;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
51
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
52 AVIFileInit();
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
53
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
54 res = AVIFileOpen(&avs->file, s->filename, OF_READ|OF_SHARE_DENY_WRITE, NULL);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
55 if (res != S_OK)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
56 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
57 av_log(s, AV_LOG_ERROR, "AVIFileOpen failed with error %ld", res);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
58 AVIFileExit();
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
59 return -1;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
60 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
61
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
62 res = AVIFileInfo(avs->file, &info, sizeof(info));
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
63 if (res != S_OK)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
64 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
65 av_log(s, AV_LOG_ERROR, "AVIFileInfo failed with error %ld", res);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
66 AVIFileExit();
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
67 return -1;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
68 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
69
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
70 avs->streams = av_mallocz(info.dwStreams * sizeof(AVISynthStream));
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
71
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
72 for (id=0; id<info.dwStreams; id++)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
73 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
74 stream = &avs->streams[id];
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
75 stream->read = 0;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
76 if (AVIFileGetStream(avs->file, &stream->handle, 0, id) == S_OK)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
77 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
78 if (AVIStreamInfo(stream->handle, &stream->info, sizeof(stream->info)) == S_OK)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
79 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
80 if (stream->info.fccType == streamtypeAUDIO)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
81 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
82 WAVEFORMATEX wvfmt;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
83 LONG struct_size = sizeof(WAVEFORMATEX);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
84 if (AVIStreamReadFormat(stream->handle, 0, &wvfmt, &struct_size) != S_OK)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
85 continue;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
86
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
87 st = av_new_stream(s, id);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
88 st->codec->codec_type = CODEC_TYPE_AUDIO;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
89
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
90 st->codec->block_align = wvfmt.nBlockAlign;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
91 st->codec->channels = wvfmt.nChannels;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
92 st->codec->sample_rate = wvfmt.nSamplesPerSec;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
93 st->codec->bit_rate = wvfmt.nAvgBytesPerSec * 8;
3917
5b915da6dd7e set bits_per_coded_sample according to new lavc api
bcoudurier
parents: 3424
diff changeset
94 st->codec->bits_per_coded_sample = wvfmt.wBitsPerSample;
1283
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
95
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
96 stream->chunck_samples = wvfmt.nSamplesPerSec * (uint64_t)info.dwScale / (uint64_t)info.dwRate;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
97 stream->chunck_size = stream->chunck_samples * wvfmt.nChannels * wvfmt.wBitsPerSample / 8;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
98
1346
3637b5c4e882 add support for some MS DIB formats for avisynth
gpoirier
parents: 1283
diff changeset
99 st->codec->codec_tag = wvfmt.wFormatTag;
3917
5b915da6dd7e set bits_per_coded_sample according to new lavc api
bcoudurier
parents: 3424
diff changeset
100 st->codec->codec_id = wav_codec_get_id(wvfmt.wFormatTag, st->codec->bits_per_coded_sample);
1283
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
101 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
102 else if (stream->info.fccType == streamtypeVIDEO)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
103 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
104 BITMAPINFO imgfmt;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
105 LONG struct_size = sizeof(BITMAPINFO);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
106
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
107 stream->chunck_size = stream->info.dwSampleSize;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
108 stream->chunck_samples = 1;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
109
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
110 if (AVIStreamReadFormat(stream->handle, 0, &imgfmt, &struct_size) != S_OK)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
111 continue;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
112
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
113 st = av_new_stream(s, id);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
114 st->codec->codec_type = CODEC_TYPE_VIDEO;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
115 st->r_frame_rate.num = stream->info.dwRate;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
116 st->r_frame_rate.den = stream->info.dwScale;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
117
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
118 st->codec->width = imgfmt.bmiHeader.biWidth;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
119 st->codec->height = imgfmt.bmiHeader.biHeight;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
120
3917
5b915da6dd7e set bits_per_coded_sample according to new lavc api
bcoudurier
parents: 3424
diff changeset
121 st->codec->bits_per_coded_sample = imgfmt.bmiHeader.biBitCount;
1283
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
122 st->codec->bit_rate = (uint64_t)stream->info.dwSampleSize * (uint64_t)stream->info.dwRate * 8 / (uint64_t)stream->info.dwScale;
1346
3637b5c4e882 add support for some MS DIB formats for avisynth
gpoirier
parents: 1283
diff changeset
123 st->codec->codec_tag = imgfmt.bmiHeader.biCompression;
3637b5c4e882 add support for some MS DIB formats for avisynth
gpoirier
parents: 1283
diff changeset
124 st->codec->codec_id = codec_get_id(codec_bmp_tags, imgfmt.bmiHeader.biCompression);
1283
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
125
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
126 st->duration = stream->info.dwLength;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
127 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
128 else
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
129 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
130 AVIStreamRelease(stream->handle);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
131 continue;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
132 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
133
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
134 avs->nb_streams++;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
135
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
136 st->codec->stream_codec_tag = stream->info.fccHandler;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
137
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
138 av_set_pts_info(st, 64, info.dwScale, info.dwRate);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
139 st->start_time = stream->info.dwStart;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
140 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
141 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
142 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
143
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
144 return 0;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
145 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
146
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
147 static int avisynth_read_packet(AVFormatContext *s, AVPacket *pkt)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
148 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
149 AVISynthContext *avs = s->priv_data;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
150 HRESULT res;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
151 AVISynthStream *stream;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
152 int stream_id = avs->next_stream;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
153 LONG read_size;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
154
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
155 // handle interleaving manually...
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
156 stream = &avs->streams[stream_id];
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
157
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
158 if (stream->read >= stream->info.dwLength)
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 1358
diff changeset
159 return AVERROR(EIO);
1283
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
160
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
161 if (av_new_packet(pkt, stream->chunck_size))
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 1358
diff changeset
162 return AVERROR(EIO);
1283
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
163 pkt->stream_index = stream_id;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
164 pkt->pts = avs->streams[stream_id].read / avs->streams[stream_id].chunck_samples;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
165
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
166 res = AVIStreamRead(stream->handle, stream->read, stream->chunck_samples, pkt->data, stream->chunck_size, &read_size, NULL);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
167
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
168 pkt->pts = stream->read;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
169 pkt->size = read_size;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
170
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
171 stream->read += stream->chunck_samples;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
172
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
173 // prepare for the next stream to read
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
174 do {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
175 avs->next_stream = (avs->next_stream+1) % avs->nb_streams;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
176 } while (avs->next_stream != stream_id && s->streams[avs->next_stream]->discard >= AVDISCARD_ALL);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
177
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
178 return (res == S_OK) ? pkt->size : -1;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
179 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
180
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
181 static int avisynth_read_close(AVFormatContext *s)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
182 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
183 AVISynthContext *avs = s->priv_data;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
184 int i;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
185
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
186 for (i=0;i<avs->nb_streams;i++)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
187 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
188 AVIStreamRelease(avs->streams[i].handle);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
189 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
190
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
191 av_free(avs->streams);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
192 AVIFileRelease(avs->file);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
193 AVIFileExit();
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
194 return 0;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
195 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
196
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
197 static int avisynth_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
198 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
199 AVISynthContext *avs = s->priv_data;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
200 int stream_id;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
201
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
202 for (stream_id = 0; stream_id < avs->nb_streams; stream_id++)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
203 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
204 avs->streams[stream_id].read = pts * avs->streams[stream_id].chunck_samples;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
205 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
206
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
207 return 0;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
208 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
209
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
210 AVInputFormat avisynth_demuxer = {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
211 "avs",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 2274
diff changeset
212 NULL_IF_CONFIG_SMALL("AVISynth"),
1283
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
213 sizeof(AVISynthContext),
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
214 NULL,
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
215 avisynth_read_header,
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
216 avisynth_read_packet,
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
217 avisynth_read_close,
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
218 avisynth_read_seek,
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
219 NULL,
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
220 0,
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
221 "avs",
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
222 };