Revision 2940b38e

View differences:

libavformat/ffm.h
32 32
#define FRAME_HEADER_SIZE    8
33 33
#define FLAG_KEY_FRAME       0x01
34 34

  
35
typedef struct FFMStream {
36
    int64_t pts;
37
} FFMStream;
38

  
39 35
enum {
40 36
    READ_HEADER,
41 37
    READ_DATA,
......
55 51
    int64_t pts;
56 52
    uint8_t *packet_ptr, *packet_end;
57 53
    uint8_t packet[FFM_PACKET_SIZE];
54
    int64_t start_time;
58 55
} FFMContext;
59 56

  
60 57
#endif /* FFMPEG_FFM_H */
libavformat/ffmdec.c
232 232
{
233 233
    FFMContext *ffm = s->priv_data;
234 234
    AVStream *st;
235
    FFMStream *fst;
236 235
    ByteIOContext *pb = s->pb;
237 236
    AVCodecContext *codec;
238 237
    int i, nb_streams;
......
263 262
        st = av_new_stream(s, 0);
264 263
        if (!st)
265 264
            goto fail;
266
        fst = av_mallocz(sizeof(FFMStream));
267
        if (!fst)
268
            goto fail;
269 265
        s->streams[i] = st;
270 266

  
271 267
        av_set_pts_info(st, 64, 1, 1000000);
272 268

  
273
        st->priv_data = fst;
274

  
275 269
        codec = st->codec;
276 270
        /* generic info */
277 271
        codec->codec_id = get_be32(pb);
libavformat/ffmenc.c
92 92
{
93 93
    FFMContext *ffm = s->priv_data;
94 94
    AVStream *st;
95
    FFMStream *fst;
96 95
    ByteIOContext *pb = s->pb;
97 96
    AVCodecContext *codec;
98 97
    int bit_rate, i;
......
116 115
    /* list of streams */
117 116
    for(i=0;i<s->nb_streams;i++) {
118 117
        st = s->streams[i];
119
        fst = av_mallocz(sizeof(FFMStream));
120
        if (!fst)
121
            goto fail;
122 118
        av_set_pts_info(st, 64, 1, 1000000);
123
        st->priv_data = fst;
124 119

  
125 120
        codec = st->codec;
126 121
        /* generic info */
......
176 171
        default:
177 172
            return -1;
178 173
        }
179
        /* hack to have real time */
180
        if (ffm_nopts)
181
            fst->pts = 0;
182
        else
183
            fst->pts = av_gettime();
184 174
    }
185 175

  
176
    /* hack to have real time */
177
    if (ffm_nopts)
178
        ffm->start_time = 0;
179
    else
180
        ffm->start_time = av_gettime();
181

  
186 182
    /* flush until end of block reached */
187 183
    while ((url_ftell(pb) % ffm->packet_size) != 0)
188 184
        put_byte(pb, 0);
......
198 194
    ffm->first_packet = 1;
199 195

  
200 196
    return 0;
201
 fail:
202
    for(i=0;i<s->nb_streams;i++) {
203
        st = s->streams[i];
204
        av_freep(&st->priv_data);
205
    }
206
    return -1;
207 197
}
208 198

  
209 199
static int ffm_write_packet(AVFormatContext *s, AVPacket *pkt)
210 200
{
201
    FFMContext *ffm = s->priv_data;
211 202
    AVStream *st = s->streams[pkt->stream_index];
212
    FFMStream *fst = st->priv_data;
213 203
    int64_t pts;
214 204
    uint8_t header[FRAME_HEADER_SIZE];
215 205

  
216
    pts = fst->pts;
206
    pts = ffm->start_time + pkt->pts;
217 207
    /* packet size & key_frame */
218 208
    header[0] = pkt->stream_index;
219 209
    header[1] = 0;
......
224 214
    ffm_write_data(s, header, FRAME_HEADER_SIZE, pts, 1);
225 215
    ffm_write_data(s, pkt->data, pkt->size, pts, 0);
226 216

  
227
    fst->pts += pkt->duration;
228 217
    return 0;
229 218
}
230 219

  
tests/libav.regression.ref
15 15
d6fdeb9f7083cc827f9510c6c4517dc0 *./tests/data/b-libav.swf
16 16
335771 ./tests/data/b-libav.swf
17 17
./tests/data/b-libav.swf CRC=0xe14e8847
18
745e811e246f3727dc80a7504a18b129 *./tests/data/b-libav.ffm
18
bf28235fdc3bdd77faf251a239b6bc58 *./tests/data/b-libav.ffm
19 19
380928 ./tests/data/b-libav.ffm
20 20
./tests/data/b-libav.ffm CRC=0xca8f6870
21 21
f8ad5bd78f4d012a8ce9570aa395ac54 *./tests/data/b-libav.flv

Also available in: Unified diff