| 382 | } |
| 383 | |
| 384 | static int ogg_write_packet(AVFormatContext *s, AVPacket *pkt) |
| 385 | { |
| 386 | AVStream *st = s->streams[pkt->stream_index]; |
| 387 | OGGStreamContext *oggstream = st->priv_data; |
| 388 | int ret; |
| 389 | int64_t granule; |
| 390 | |
| 391 | if (st->codec->codec_id == CODEC_ID_THEORA) { |
| 392 | int64_t pts = oggstream->vrev < 1 ? pkt->pts : pkt->pts + pkt->duration; |
| 393 | int pframe_count; |
| 394 | if (pkt->flags & AV_PKT_FLAG_KEY) |
| 395 | oggstream->last_kf_pts = pts; |
| 396 | pframe_count = pts - oggstream->last_kf_pts; |
| 397 | // prevent frame count from overflow if key frame flag is not set |
| 398 | if (pframe_count >= (1<<oggstream->kfgshift)) { |
| 399 | oggstream->last_kf_pts += pframe_count; |
| 400 | pframe_count = 0; |
| 401 | } |
| 402 | granule = (oggstream->last_kf_pts<<oggstream->kfgshift) | pframe_count; |
| 403 | } else |
| 404 | granule = pkt->pts + pkt->duration; |
| 405 | oggstream->duration = granule; |
| 406 | |
| 407 | ret = ogg_buffer_data(s, st, pkt->data, pkt->size, granule); |
| 408 | if (ret < 0) |
| 409 | return ret; |
| 410 | |
| 411 | ogg_write_pages(s, 0); |
| 412 | |
| 413 | return 0; |
| 414 | } |
| 415 | |
| 416 | static int ogg_write_trailer(AVFormatContext *s) |
| 417 | { |
nothing calls this directly
no test coverage detected