int state;
} MMFmemIOHandle;
+static void __count_stream_num(AVFormatContext *pFormatCtx, MMFileFormatContext *formatContext)
+{
+ unsigned int i = 0;
+
+ formatContext->videoTotalTrackNum = 0;
+ formatContext->audioTotalTrackNum = 0;
+
+ for (i = 0; i < pFormatCtx->nb_streams; i++) {
+ if (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
+ debug_msg(RELEASE, "FFMPEG video codec id: 0x%08X\n", pFormatCtx->streams[i]->codecpar->codec_id);
+
+ AVPacket pkt = pFormatCtx->streams[i]->attached_pic;
+ if ((pkt.data != NULL) && (pkt.size > 0))
+ continue;
+
+ /*eventhough codec_id is 0, avformat_find_stream_info() can find proper codec_id. */
+ formatContext->videoTotalTrackNum += 1;
+ }
+ if (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
+ debug_msg(RELEASE, "FFMPEG audio codec id: 0x%08X\n", pFormatCtx->streams[i]->codecpar->codec_id);
+ formatContext->audioTotalTrackNum += 1;
+ }
+ }
+}
+
static int _mmf_mem_open(MMFmemIOHandle **handle, const char *filename)
{
MMFmemIOHandle *memHandle = NULL;
AVFormatContext *pFormatCtx = NULL;
AVInputFormat *grab_iformat = NULL;
int ret = 0;
- unsigned int i;
char ffmpegFormatName[MMFILE_FILE_FMT_MAX_LEN] = {0, };
char mimeType[MMFILE_MIMETYPE_MAX_LEN] = {0, };
AVIOContext *pIOCtx = NULL;
memset(ffmpegFormatName, 0x00, MMFILE_FILE_FMT_MAX_LEN);
ret = mmfile_util_get_ffmpeg_format(mimeType, ffmpegFormatName);
-
if (MMFILE_UTIL_SUCCESS != ret) {
debug_error(DEBUG, "error: mmfile_util_get_ffmpeg_format\n");
return MMFILE_FORMAT_FAIL;
debug_msg(RELEASE, "number of stream: %d\n", pFormatCtx->nb_streams);
- formatContext->videoTotalTrackNum = 0;
- formatContext->audioTotalTrackNum = 0;
-
- for (i = 0; i < pFormatCtx->nb_streams; i++) {
- if (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
- debug_msg(RELEASE, "FFMPEG video codec id: 0x%08X\n", pFormatCtx->streams[i]->codecpar->codec_id);
-
- AVPacket pkt = pFormatCtx->streams[i]->attached_pic;
- if ((pkt.data != NULL) && (pkt.size > 0))
- continue;
-
- /*eventhough codec_id is 0, avformat_find_stream_info() can find proper codec_id. */
- formatContext->videoTotalTrackNum += 1;
- }
- if (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
- debug_msg(RELEASE, "FFMPEG audio codec id: 0x%08X\n", pFormatCtx->streams[i]->codecpar->codec_id);
- formatContext->audioTotalTrackNum += 1;
- }
- }
+ __count_stream_num(pFormatCtx, formatContext);
debug_msg(RELEASE, "format: %s (%s)\n", pFormatCtx->iformat->name, pFormatCtx->iformat->long_name);
#ifdef __MMFILE_TEST_MODE__
if (ret < 0) {
debug_error(DEBUG, "read failed. (maybe EOF or broken)\n");
break;
- } else {
- 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)) {
- debug_msg(RELEASE, "video frame: %d, %d, %d\n", retry, i, v);
+ }
+
+ 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)) {
+ debug_msg(RELEASE, "video frame: %d, %d, %d\n", retry, i, v);
#ifdef __MMFILE_TEST_MODE__
- _dump_av_packet(&pkt);
+ _dump_av_packet(&pkt);
#endif
- i++;
- key_detected = 0;
+ i++;
+ key_detected = 0;
- 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;
- }
+ 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;
+ }
- len = avcodec_receive_frame(pCodecCtx, frame);
- if (len < 0 && len != AVERROR(EAGAIN) && len != AVERROR_EOF) {
- debug_warning(DEBUG, "Error while decoding frame %dth\n", i);
- } else if (len >= 0) {
- if (frame->key_frame) {
- debug_msg(RELEASE, "key frame!\n");
+ len = avcodec_receive_frame(pCodecCtx, frame);
+ if (len < 0 && len != AVERROR(EAGAIN) && len != AVERROR_EOF) {
+ debug_warning(DEBUG, "Error while decoding frame %dth\n", i);
+ } else if (len >= 0) {
+ if (frame->key_frame) {
+ debug_msg(RELEASE, "key frame!\n");
#ifdef MMFILE_FORMAT_DEBUG_DUMP
- memset(pgm_name, 0x00, sizeof(pgm_name));
- snprintf(pgm_name, sizeof(pgm_name), "./key_%d_%d_%d.pgm", retry, i, v);
- _save_pgm(frame->data[0], frame->linesize[0], pCodecCtx->width, pCodecCtx->height, pgm_name);
+ memset(pgm_name, 0x00, sizeof(pgm_name));
+ snprintf(pgm_name, sizeof(pgm_name), "./key_%d_%d_%d.pgm", retry, i, v);
+ _save_pgm(frame->data[0], frame->linesize[0], pCodecCtx->width, pCodecCtx->height, pgm_name);
#endif
- found++;
+ found++;
#ifdef __MMFILE_TEST_MODE__
- int64_t ti;
- ti = gettime();
+ int64_t ti;
+ ti = gettime();
#endif
- ret = _is_good_pgm(frame->data[0], frame->linesize[0], pCodecCtx->width, pCodecCtx->height);
+ ret = _is_good_pgm(frame->data[0], frame->linesize[0], pCodecCtx->width, pCodecCtx->height);
#ifdef __MMFILE_TEST_MODE__
- ti = gettime() - ti;
- debug_msg(RELEASE, "Elapsed time = %lld\n", ti);
-#endif
- if (ret != 0) {
- debug_msg(RELEASE, "is good frame.\n");
- break;
- } else {
- /*reset video frame count & retry searching*/
- debug_warning(RELEASE, "not good fame. retry scanning.\n");
- i = 0;
- v = 0;
- retry++;
- }
-
- /*set buffer frame*/
- frame = tmp_frame;
-
- /*limit of retry.*/
- if (retry > _RETRY_SEARCH_LIMIT) break;
-
- } else {
- debug_msg(RELEASE, "skip (not key frame).\n");
-#ifdef MMFILE_FORMAT_DEBUG_DUMP
- memset(pgm_name, 0x00, sizeof(pgm_name));
- snprintf(pgm_name, sizeof(pgm_name), "./not_key_%d_%d_%d.pgm", retry, i, v);
- _save_pgm(frame->data[0], frame->linesize[0], pCodecCtx->width, pCodecCtx->height, pgm_name);
+ ti = gettime() - ti;
+ debug_msg(RELEASE, "Elapsed time = %lld\n", ti);
#endif
+ if (ret != 0) {
+ debug_msg(RELEASE, "is good frame.\n");
+ break;
}
+
+ /*reset video frame count & retry searching*/
+ debug_warning(RELEASE, "not good fame. retry scanning.\n");
+ i = 0;
+ v = 0;
+ retry++;
+
+ /*set buffer frame*/
+ frame = tmp_frame;
+
+ /*limit of retry.*/
+ if (retry > _RETRY_SEARCH_LIMIT) break;
+
} else {
- debug_msg(RELEASE, "decode not completed.\n");
- key_detected = 1;
+ debug_msg(RELEASE, "skip (not key frame).\n");
+#ifdef MMFILE_FORMAT_DEBUG_DUMP
+ memset(pgm_name, 0x00, sizeof(pgm_name));
+ snprintf(pgm_name, sizeof(pgm_name), "./not_key_%d_%d_%d.pgm", retry, i, v);
+ _save_pgm(frame->data[0], frame->linesize[0], pCodecCtx->width, pCodecCtx->height, pgm_name);
+#endif
}
+ } else {
+ debug_msg(RELEASE, "decode not completed.\n");
+ key_detected = 1;
}
}
}
+
av_packet_unref(&pkt);
}