Revision 20f01548 libav/ffm.c

View differences:

libav/ffm.c
24 24
#define PACKET_ID       0x666d
25 25

  
26 26
/* each packet contains frames (which can span several packets */
27
#define FRAME_HEADER_SIZE    5
27
#define FRAME_HEADER_SIZE    8
28 28
#define FLAG_KEY_FRAME       0x01
29 29

  
30 30
typedef struct FFMStream {
......
159 159
            put_be32(pb, (codec->frame_rate * 1000) / FRAME_RATE_BASE);
160 160
            put_be16(pb, codec->width);
161 161
            put_be16(pb, codec->height);
162
	    put_byte(pb, codec->qmin);
163
	    put_byte(pb, codec->qmax);
164
	    put_byte(pb, codec->max_qdiff);
165
	    put_be16(pb, (int) (codec->qcompress * 10000.0));
166
	    put_be16(pb, (int) (codec->qblur * 10000.0));
162
            put_be16(pb, codec->gop_size);
163
            put_byte(pb, codec->qmin);
164
            put_byte(pb, codec->qmax);
165
            put_byte(pb, codec->max_qdiff);
166
            put_be16(pb, (int) (codec->qcompress * 10000.0));
167
            put_be16(pb, (int) (codec->qblur * 10000.0));
167 168
            break;
168 169
        case CODEC_TYPE_AUDIO:
169 170
            put_be32(pb, codec->sample_rate);
170 171
            put_le16(pb, codec->channels);
172
            put_le16(pb, codec->frame_size);
171 173
            break;
174
        default:
175
            abort();
172 176
        }
173 177
        /* hack to have real time */
174 178
        fst->pts = gettime();
......
206 210
    FFMStream *fst = st->priv_data;
207 211
    INT64 pts;
208 212
    UINT8 header[FRAME_HEADER_SIZE];
213
    int duration;
214

  
215
    if (st->codec.codec_type == CODEC_TYPE_AUDIO) {
216
        duration = ((float)st->codec.frame_size / st->codec.sample_rate * 1000000.0);
217
    } else {
218
        duration = (1000000.0 * FRAME_RATE_BASE / (float)st->codec.frame_rate);
219
    }
209 220

  
210 221
    pts = fst->pts;
211 222
    /* packet size & key_frame */
......
216 227
    header[2] = (size >> 16) & 0xff;
217 228
    header[3] = (size >> 8) & 0xff;
218 229
    header[4] = size & 0xff;
230
    header[5] = (duration >> 16) & 0xff;
231
    header[6] = (duration >> 8) & 0xff;
232
    header[7] = duration & 0xff;
219 233
    ffm_write_data(s, header, FRAME_HEADER_SIZE, pts, 1);
220 234
    ffm_write_data(s, buf, size, pts, 0);
221 235

  
222
    if (st->codec.codec_type == CODEC_TYPE_AUDIO) {
223
        fst->pts += (INT64)((float)st->codec.frame_size / st->codec.sample_rate * 1000000.0);
224
    } else {
225
        fst->pts += (INT64)(1000000.0 * FRAME_RATE_BASE / (float)st->codec.frame_rate);
226
    }
236
    fst->pts += duration;
227 237
    return 0;
228 238
}
229 239

  
......
372 382
            codec->frame_rate = ((INT64)get_be32(pb) * FRAME_RATE_BASE) / 1000;
373 383
            codec->width = get_be16(pb);
374 384
            codec->height = get_be16(pb);
375
	    codec->qmin = get_byte(pb);
376
	    codec->qmax = get_byte(pb);
377
	    codec->max_qdiff = get_byte(pb);
378
	    codec->qcompress = get_be16(pb) / 10000.0;
379
	    codec->qblur = get_be16(pb) / 10000.0;
385
            codec->gop_size = get_be16(pb);
386
            codec->qmin = get_byte(pb);
387
            codec->qmax = get_byte(pb);
388
            codec->max_qdiff = get_byte(pb);
389
            codec->qcompress = get_be16(pb) / 10000.0;
390
            codec->qblur = get_be16(pb) / 10000.0;
380 391
            break;
381 392
        case CODEC_TYPE_AUDIO:
382 393
            codec->sample_rate = get_be32(pb);
383 394
            codec->channels = get_le16(pb);
395
            codec->frame_size = get_le16(pb);
384 396
            break;
397
        default:
398
            abort();
385 399
        }
386 400

  
387 401
    }
......
418 432
{
419 433
    int size;
420 434
    FFMContext *ffm = s->priv_data;
435
    int duration;
421 436

  
422 437
    switch(ffm->read_state) {
423 438
    case READ_HEADER:
......
446 461
            return -EAGAIN;
447 462
        }
448 463

  
464
        duration = (ffm->header[5] << 16) | (ffm->header[6] << 8) | ffm->header[7];
465

  
449 466
        av_new_packet(pkt, size);
450 467
        pkt->stream_index = ffm->header[0];
451 468
        if (ffm->header[1] & FLAG_KEY_FRAME)
......
457 474
            av_free_packet(pkt);
458 475
            return -EAGAIN;
459 476
        }
477
        pkt->pts = ffm->pts;
478
        pkt->duration = duration;
460 479
        break;
461 480
    }
462 481
    return 0;

Also available in: Unified diff