| 6385 | } |
| 6386 | |
| 6387 | hb_buffer_t * hb_ffmpeg_read( hb_stream_t *stream ) |
| 6388 | { |
| 6389 | int err; |
| 6390 | hb_buffer_t * buf; |
| 6391 | |
| 6392 | again: |
| 6393 | if ( ( err = av_read_frame( stream->ffmpeg_ic, stream->ffmpeg_pkt )) < 0 ) |
| 6394 | { |
| 6395 | // av_read_frame can return EAGAIN. In this case, it expects |
| 6396 | // to be called again to get more data. |
| 6397 | if ( err == AVERROR(EAGAIN) ) |
| 6398 | { |
| 6399 | goto again; |
| 6400 | } |
| 6401 | // XXX the following conditional is to handle avi files that |
| 6402 | // use M$ 'packed b-frames' and occasionally have negative |
| 6403 | // sizes for the null frames these require. |
| 6404 | if ( err != AVERROR(ENOMEM) || stream->ffmpeg_pkt->size >= 0 ) |
| 6405 | { |
| 6406 | // error or eof |
| 6407 | if (err != AVERROR_EOF) |
| 6408 | { |
| 6409 | char errstr[80]; |
| 6410 | av_strerror(err, errstr, 80); |
| 6411 | hb_error("av_read_frame error (%d): %s", err, errstr); |
| 6412 | hb_set_work_error(stream->h, HB_ERROR_READ); |
| 6413 | } |
| 6414 | return NULL; |
| 6415 | } |
| 6416 | } |
| 6417 | if ( stream->ffmpeg_pkt->stream_index == stream->ffmpeg_video_id ) |
| 6418 | { |
| 6419 | if ( stream->need_keyframe ) |
| 6420 | { |
| 6421 | // we've just done a seek (generally for scan or live preview) and |
| 6422 | // want to start at a keyframe. Some ffmpeg codecs seek to a key |
| 6423 | // frame but most don't. So we spin until we either get a keyframe |
| 6424 | // or we've looked through 50 video frames without finding one. |
| 6425 | if ( ! ffmpeg_is_keyframe( stream ) && ++stream->need_keyframe < 50 ) |
| 6426 | { |
| 6427 | av_packet_unref(stream->ffmpeg_pkt); |
| 6428 | goto again; |
| 6429 | } |
| 6430 | stream->need_keyframe = 0; |
| 6431 | } |
| 6432 | ++stream->frames; |
| 6433 | } |
| 6434 | AVStream *s = stream->ffmpeg_ic->streams[stream->ffmpeg_pkt->stream_index]; |
| 6435 | if ( stream->ffmpeg_pkt->size <= 0 ) |
| 6436 | { |
| 6437 | // M$ "invalid and inefficient" packed b-frames require 'null frames' |
| 6438 | // following them to preserve the timing (since the packing puts two |
| 6439 | // or more frames in what looks like one avi frame). The contents and |
| 6440 | // size of these null frames are ignored by the ff_h263_decode_frame |
| 6441 | // as long as they're < 20 bytes. Zero length buffers are also |
| 6442 | // use by theora to indicate duplicate frames. |
| 6443 | buf = hb_buffer_init( 0 ); |
| 6444 | } |
no test coverage detected