#include <libavformat/url.h>
#include <libavcodec/avcodec.h>
#include <libavutil/samplefmt.h>
-#ifdef __MMFILE_FFMPEG_V085__
#include <libswscale/swscale.h>
-#endif
#include <mm_error.h>
#include <mm_types.h>
#include "mm_file_debug.h"
#define _SHORT_MEDIA_LIMIT 2000 /* under X seconds duration*/
-extern int img_convert(AVPicture *dst, int dst_pix_fmt, const AVPicture *src, int src_pix_fmt, int src_width, int src_height);
-
/* internal functions */
static int _is_good_pgm(unsigned char *buf, int wrap, int xsize, int ysize);
#ifdef MMFILE_FORMAT_DEBUG_DUMP
if (formatContext->filesrc->type == MM_FILE_SRC_TYPE_MEMORY) {
-#if (defined __MMFILE_FFMPEG_V085__ && !defined __MMFILE_LIBAV_VERSION__)
- ffurl_register_protocol(&MMFileMEMProtocol, sizeof(URLProtocol));
-#else
ffurl_register_protocol(&MMFileMEMProtocol);
-#endif
+
if (getMimeType(formatContext->filesrc->memory.format, mimeType, MMFILE_MIMETYPE_MAX_LEN) < 0) {
debug_error(DEBUG, "error: Error in MIME Type finding\n");
return MMFILE_FORMAT_FAIL;
goto exception;
}
-#ifdef __MMFILE_FFMPEG_V085__
ret = avformat_open_input(&pFormatCtx, formatContext->uriFileName, grab_iformat, NULL);
-#else
- ret = av_open_input_file(&pFormatCtx, formatContext->uriFileName, grab_iformat, 0, NULL);
-#endif
if (ret < 0) {
debug_error(DEBUG, "error: cannot open %s %d\n", formatContext->uriFileName, ret);
goto exception;
}
if (formatContext->filesrc->type == MM_FILE_SRC_TYPE_FILE) {
-#ifdef __MMFILE_FFMPEG_V085__
+
ret = avformat_open_input(&pFormatCtx, formatContext->filesrc->file.path, NULL, NULL);
-#else
- ret = av_open_input_file(&pFormatCtx, formatContext->filesrc->file.path, NULL, 0, NULL);
-#endif
if (ret < 0) {
debug_error(DEBUG, "error: cannot open %s %d\n", formatContext->filesrc->file.path, ret);
goto exception;
formatContext->audioTotalTrackNum = 0;
for (i = 0; i < pFormatCtx->nb_streams; i++) {
-#ifdef __MMFILE_FFMPEG_V085__
if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
debug_msg(RELEASE, "FFMPEG video codec id: 0x%08X\n", pFormatCtx->streams[i]->codec->codec_id);
debug_msg(RELEASE, "FFMPEG audio codec id: 0x%08X\n", pFormatCtx->streams[i]->codec->codec_id);
formatContext->audioTotalTrackNum += 1;
}
-#else
- if (pFormatCtx->streams[i]->codec->codec_type == AV_CODEC_TYPE_VIDEO) {
- debug_msg(RELEASE, "FFMPEG video codec id: 0x%08X\n", pFormatCtx->streams[i]->codec->codec_id);
- formatContext->videoTotalTrackNum += 1;
- }
- if (pFormatCtx->streams[i]->codec->codec_type == AV_CODEC_TYPE_AUDIO) {
- debug_msg(RELEASE, "FFMPEG audio codec id: 0x%08X\n", pFormatCtx->streams[i]->codec->codec_id);
- formatContext->audioTotalTrackNum += 1;
- }
-#endif
}
debug_msg(RELEASE, "format: %s (%s)\n", pFormatCtx->iformat->name, pFormatCtx->iformat->long_name);
#ifdef __MMFILE_TEST_MODE__
-#ifdef __MMFILE_FFMPEG_V085__
av_dump_format(pFormatCtx, 0, formatContext->filesrc->file.path, 0);
-#else
- dump_format(pFormatCtx, 0, formatContext->filesrc->file.path, 0);
-#endif
#endif
return MMFILE_FORMAT_SUCCESS;
unsigned int i = 0;
for (i = 0; i < pFormatCtx->nb_streams; i++) {
-#ifdef __MMFILE_FFMPEG_V085__
if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
-#else
- if (pFormatCtx->streams[i]->codec->codec_type == AV_CODEC_TYPE_VIDEO) {
-#endif
if (formatContext->videoStreamId == -1) {
videoStream = mmfile_malloc(sizeof(MMFileFormatStream));
if (NULL == videoStream) {
}
}
}
-#ifdef __MMFILE_FFMPEG_V085__
else if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
-#else
- else if (pFormatCtx->streams[i]->codec->codec_type == AV_CODEC_TYPE_AUDIO) {
-#endif
if (formatContext->audioStreamId == -1) {
audioStream = mmfile_malloc(sizeof(MMFileFormatStream));
if (NULL == audioStream) {
MMFileUtilGetMetaDataFromMP4(formatContext);
}
-#ifdef __MMFILE_FFMPEG_V085__
/*metadata extracted by ffmpeg*/
unsigned int idx = 0;
#endif
}
}
-#else
- if (pFormatCtx->title[0]) {
- if (formatContext->title)
- free(formatContext->title);
- formatContext->title = mmfile_strdup(pFormatCtx->title);
- }
- if (pFormatCtx->author[0]) {
- if (formatContext->author)
- free(formatContext->author);
- formatContext->author = mmfile_strdup(pFormatCtx->author);
- }
- if (pFormatCtx->copyright[0]) {
- if (formatContext->copyright)
- free(formatContext->copyright);
- formatContext->copyright = mmfile_strdup(pFormatCtx->copyright);
- }
- if (pFormatCtx->comment[0]) {
- if (formatContext->comment)
- free(formatContext->comment);
- formatContext->comment = mmfile_strdup(pFormatCtx->comment);
- }
- if (pFormatCtx->album[0]) {
- if (formatContext->album)
- free(formatContext->album);
- formatContext->album = mmfile_strdup(pFormatCtx->album);
- }
- if (pFormatCtx->genre[0]) {
- if (formatContext->genre)
- free(formatContext->genre);
- formatContext->genre = mmfile_strdup(pFormatCtx->genre);
- }
-
- if (pFormatCtx->year) {
- char year[10] = {0, };
- snprintf(year, 10, "%d", pFormatCtx->year);
- year[9] = '\0';
- if (formatContext->year)
- free(formatContext->year);
- formatContext->year = mmfile_strdup(year);
- }
-
- if (pFormatCtx->track) {
- char tracknum[10] = {0, };
- snprintf(tracknum, 10, "%d", pFormatCtx->track);
- tracknum[9] = '\0';
- if (formatContext->tagTrackNum)
- free(formatContext->tagTrackNum);
- formatContext->tagTrackNum = mmfile_strdup(tracknum);
- }
-#endif
return MMFILE_FORMAT_SUCCESS;
}
goto exception;
}
-#ifdef __MMFILE_FFMPEG_V085__
struct SwsContext *img_convert_ctx = NULL;
img_convert_ctx = sws_getContext(width, height, pVideoCodecCtx->pix_fmt, width, height, AV_PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL);
sws_freeContext(img_convert_ctx);
img_convert_ctx = NULL;
-#else
- ret = img_convert((AVPicture *)pFrameRGB, AV_PIX_FMT_RGB24, (AVPicture *)pFrame, pVideoCodecCtx->pix_fmt, width, height);
- if (ret < 0) {
- debug_error(DEBUG, "failed to convet image\n");
- ret = MMFILE_FORMAT_FAIL;
- goto exception;
- }
-#endif
+
frame->frameSize = numBytes;
frame->frameWidth = width;
frame->frameHeight = height;
debug_msg(RELEASE, " data: %p\n", pkt->data);
debug_msg(RELEASE, " size: %d\n", pkt->size);
debug_msg(RELEASE, " stream_index: %d\n", pkt->stream_index);
-#ifdef __MMFILE_FFMPEG_V085__
debug_msg(RELEASE, " flags: 0x%08X, %s\n", pkt->flags, (pkt->flags & AV_PKT_FLAG_KEY) ? "Keyframe" : "_");
-#else
- debug_msg(RELEASE, " flags: 0x%08X, %s\n", pkt->flags, (pkt->flags & PKT_FLAG_KEY) ? "Keyframe" : "_");
-#endif
debug_msg(RELEASE, " duration: %d\n", pkt->duration);
/*debug_msg(RELEASE, " destruct: %p\n", pkt->destruct);*/
/*debug_msg(RELEASE, " priv: %p\n", pkt->priv);*/
debug_msg(RELEASE, "frame: 1. %p, 2. %p\n", first_frame, tmp_frame);
-#ifdef __MMFILE_FFMPEG_V085__
pCodecCtx->skip_frame = AVDISCARD_BIDIR;
-#else
- pCodecCtx->hurry_up = 1;
-#endif
if (cdis == 1) {
key_search_limit = _KEY_SEARCH_LIMIT_CDIS;
} else {
if (avcodec_get_type(pFormatCtx->streams[pkt.stream_index]->codec->codec_id) == AVMEDIA_TYPE_VIDEO) {
v++;
-#ifdef __MMFILE_FFMPEG_V085__
if ((pkt.flags & AV_PKT_FLAG_KEY) || (key_detected == 1))
-#else
- if ((pkt.flags & PKT_FLAG_KEY) || (key_detected == 1))
-#endif
{
debug_msg(RELEASE, "video frame: %d, %d, %d\n", retry, i, v);
#ifdef __MMFILE_TEST_MODE__
i++;
key_detected = 0;
-#ifdef __MMFILE_FFMPEG_V085__
+
len = avcodec_decode_video2(pCodecCtx, frame, &got_picture, &pkt);
-#else
- len = avcodec_decode_video(pCodecCtx, frame, &got_picture, pkt.data, pkt.size);
-#endif
if (len < 0) {
debug_warning(DEBUG, "Error while decoding frame %dth\n", i);
} else if (got_picture) {
debug_msg(RELEASE, "out frame: %p\n", *pFrame);
-#ifdef __MMFILE_FFMPEG_V085__
pCodecCtx->skip_frame = AVDISCARD_NONE;
-#else
- pCodecCtx->hurry_up = 0;
-#endif
return ret;
}
case AV_CODEC_ID_CINEPAK:
ret_codecid = MM_VIDEO_CODEC_CINEPAK;
break;
-#if (!defined __MMFILE_FFMPEG_V085__ && !defined __MMFILE_LIBAV_VERSION__)
- case AV_CODEC_ID_XVID:
- ret_codecid = MM_VIDEO_CODEC_XVID;
- break;
-#endif
case AV_CODEC_ID_VC1:
ret_codecid = MM_VIDEO_CODEC_VC1;
break;