#define _FRAME_SEARCH_LIMIT_CDIS 10
/* AVStream *st = NULL; */
- AVPacket pkt;
+ AVPacket *pkt = NULL;
AVFrame *frame = NULL;
AVFrame *tmp_frame = NULL;
pCodecCtx->skip_frame = AVDISCARD_BIDIR;
for (i = 0, v = 0, key_detected = 0, frame = first_frame; i < key_search_limit && v < frame_search_limit;) {
- av_init_packet(&pkt);
+ pkt = av_packet_alloc();
+ if (!pkt) {
+ debug_error(DEBUG, "packet allocation failed.");
+ break;
+ }
- ret = av_read_frame(pFormatCtx, &pkt);
+ ret = av_read_frame(pFormatCtx, pkt);
if (ret < 0) {
debug_error(DEBUG, "read failed. (maybe EOF or broken)");
break;
}
- if (avcodec_get_type(pFormatCtx->streams[pkt.stream_index]->codecpar->codec_id) == AVMEDIA_TYPE_VIDEO) {
+ if (avcodec_get_type(pFormatCtx->streams[pkt->stream_index]->codecpar->codec_id) == AVMEDIA_TYPE_VIDEO) {
v++;
- if ((pkt.flags & AV_PKT_FLAG_KEY) || (key_detected == 1)) {
+ if ((pkt->flags & AV_PKT_FLAG_KEY) || (key_detected == 1)) {
debug_msg(RELEASE, "video frame: %d, %d, %d", retry, i, v);
#ifdef __MMFILE_TEST_MODE__
- _dump_av_packet(&pkt);
+ _dump_av_packet(pkt);
#endif
i++;
key_detected = 0;
- len = avcodec_send_packet(pCodecCtx, &pkt);
+ len = avcodec_send_packet(pCodecCtx, pkt);
if (len < 0 && len != AVERROR(EAGAIN) && len != AVERROR_EOF) {
debug_error(RELEASE, "Error while avcodec_send_packet[%2d]", len);
break;
}
}
- av_packet_unref(&pkt);
+ av_packet_free(&pkt);
}
/*free pkt after loop breaking*/
- av_packet_unref(&pkt);
+ av_packet_free(&pkt);
debug_msg(RELEASE, "found: %d, retry: %d", found, retry);
AVFrame *pFrame)
{
bool find = false;
- AVPacket packet;
+ AVPacket *packet;
AVStream *pStream = NULL;
bool first_seek = true;
int64_t pts = 0;
#endif
pStream = pFormatCtx->streams[videoStream];
- av_init_packet(&packet);
+ packet = av_packet_alloc();
+ mm_file_retvm_if_fails(RELEASE, packet, false);
- while (av_read_frame(pFormatCtx, &packet) >= 0) {
+ while (av_read_frame(pFormatCtx, packet) >= 0) {
/* Is this a packet from the video stream? */
- if (packet.stream_index == videoStream) {
+ if (packet->stream_index == videoStream) {
#ifdef __MMFILE_TEST_MODE__
debug_msg(RELEASE, "find Video Stream+++++++[%2d]", idx++);
#endif
/* Decode video frame*/
- len = avcodec_send_packet(pVideoCodecCtx, &packet);
+ len = avcodec_send_packet(pVideoCodecCtx, packet);
if (len < 0 && len != AVERROR(EAGAIN) && len != AVERROR_EOF) {
debug_error(RELEASE, "Error while avcodec_send_packet[%2d]", len);
break;
if (len < 0 && len != AVERROR(EAGAIN) && len != AVERROR_EOF) {
debug_warning(DEBUG, "Error while avcodec_receive_frame");
} else if (len >= 0) {
- if ((packet.flags & AV_PKT_FLAG_KEY)) {
+ if ((packet->flags & AV_PKT_FLAG_KEY)) {
if (first_seek || !is_accurate) {
/* This is first seeking or not accurate mode.
} else {
if (is_accurate) {
if (first_seek) {
- pts = (packet.pts == (int64_t)AV_NOPTS_VALUE) ? (packet.dts * av_q2d(pStream->time_base)) : packet.pts;
+ pts = (packet->pts == (int64_t)AV_NOPTS_VALUE) ? (packet->dts * av_q2d(pStream->time_base)) : packet->pts;
first_seek = false;
av_seek_frame(pFormatCtx, -1, pos, AVSEEK_FLAG_BACKWARD);
} else {
- tmpPts = (packet.pts == (int64_t)AV_NOPTS_VALUE) ? (packet.dts * av_q2d(pStream->time_base)) : packet.pts;
+ tmpPts = (packet->pts == (int64_t)AV_NOPTS_VALUE) ? (packet->dts * av_q2d(pStream->time_base)) : packet->pts;
if (pts == tmpPts)
find = true;
}
break;
}
- /* Free the packet that was allocated by av_read_frame*/
- av_packet_unref(&packet);
- av_init_packet(&packet);
+ av_packet_unref(packet);
}
- /*free pkt after loop breaking*/
- av_packet_unref(&packet);
+ /*free packet after loop */
+ av_packet_free(&packet);
return find;
}