From: Hyunjun Ko Date: Sat, 23 Mar 2013 06:51:20 +0000 (+0900) Subject: 1. Add to handle the case that there is wrong video stream X-Git-Tag: 2.1b_release~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=94ed05c584166aa58380ea1ab1f5344932e5ab4e;p=platform%2Fcore%2Fmultimedia%2Flibmm-fileinfo.git 1. Add to handle the case that there is wrong video stream 2. Add to handle Info attr in header to get duration Change-Id: Ibed0d99f0b47db76de5befc827fbdb98b96ef9ee --- diff --git a/formats/ffmpeg/mm_file_format_ffmpeg.c b/formats/ffmpeg/mm_file_format_ffmpeg.c index 18cb964..123d7c2 100755 --- a/formats/ffmpeg/mm_file_format_ffmpeg.c +++ b/formats/ffmpeg/mm_file_format_ffmpeg.c @@ -296,6 +296,14 @@ int mmfile_format_read_stream_ffmpg (MMFileFormatContext * formatContext) pVideoCodecCtx = pFormatCtx->streams[i]->codec; if (pVideoCodecCtx) { videoStream->codecId = ConvertVideoCodecEnum (pVideoCodecCtx->codec_id); + if (videoStream->codecId == MM_VIDEO_CODEC_NONE) { + debug_error("Proper codec is not found in [%d] stream", i); + formatContext->videoStreamId = -1; + mmfile_free(videoStream); + formatContext->streams[MMFILE_VIDEO_STREAM] = NULL; + videoStream = NULL; + continue; + } /** * Get FPS diff --git a/formats/ffmpeg/mm_file_format_mp3.c b/formats/ffmpeg/mm_file_format_mp3.c index 48d4548..4dcfb8d 100755 --- a/formats/ffmpeg/mm_file_format_mp3.c +++ b/formats/ffmpeg/mm_file_format_mp3.c @@ -315,10 +315,19 @@ __AvGetXingHeader( AvXHeadData* headData, unsigned char *buf ) buf += (9+4); } - if( buf[0] != 'X' ) return 0; // fail - if( buf[1] != 'i' ) return 0; // header not found - if( buf[2] != 'n' ) return 0; - if( buf[3] != 'g' ) return 0; + /* There could be 2 attrs in this header : Xing or Info */ + if (buf[0] == 'X') { + if( buf[1] != 'i' ) return 0; + if( buf[2] != 'n' ) return 0; + if( buf[3] != 'g' ) return 0; + } else if (buf[0] == 'I') { + if( buf[1] != 'n' ) return 0; + if( buf[2] != 'f' ) return 0; + if( buf[3] != 'o' ) return 0; + } else { + return 0; + } + buf += 4; headData->hId = hId; @@ -579,35 +588,57 @@ __AvParseXingHeader( AvFileContentInfo* pInfo, unsigned char* buf ) AvXHeadData data; memset( &data, 0x00, sizeof(AvXHeadData) ); - // 1. Xing Header üũ + // 1. Xing Header + /* There could be 2 attrs in this header : Xing or Info */ if((pInfo->mpegVersion == AV_MPEG_VER_1) && (pInfo->channels == 2)) { - if( buf[36] != 'X' ) return false; - if( buf[37] != 'i' ) return false; - if( buf[38] != 'n' ) return false; - if( buf[39] != 'g' ) return false; + if (buf[36] =='X') { + if( buf[37] != 'i' ) return false; + if( buf[38] != 'n' ) return false; + if( buf[39] != 'g' ) return false; + } else if (buf[36] == 'I') { + if( buf[37] != 'n' ) return false; + if( buf[38] != 'f' ) return false; + if( buf[39] != 'o' ) return false; + } else { + return false; + } } else if((pInfo->mpegVersion == AV_MPEG_VER_2) && (pInfo->channels == 1)) { - if( buf[13] != 'X' ) return false; - if( buf[14] != 'i' ) return false; - if( buf[15] != 'n' ) return false; - if( buf[16] != 'g' ) return false; + if (buf[13] =='X') { + if( buf[14] != 'i' ) return false; + if( buf[15] != 'n' ) return false; + if( buf[16] != 'g' ) return false; + } else if (buf[13] == 'I') { + if( buf[14] != 'n' ) return false; + if( buf[15] != 'f' ) return false; + if( buf[16] != 'o' ) return false; + } else { + return false; + } } else { - if( buf[21] != 'X' ) return false; - if( buf[22] != 'i' ) return false; - if( buf[23] != 'n' ) return false; - if( buf[24] != 'g' ) return false; + if (buf[21] =='X') { + if( buf[22] != 'i' ) return false; + if( buf[23] != 'n' ) return false; + if( buf[24] != 'g' ) return false; + } else if (buf[21] == 'I') { + if( buf[22] != 'n' ) return false; + if( buf[23] != 'f' ) return false; + if( buf[24] != 'o' ) return false; + } else { + return false; + } } - // 2. TOC�� ����ұ� + // 2. TOC if ( pInfo->pToc ) data.toc = (unsigned char *)(pInfo->pToc); - if ( __AvGetXingHeader( &data, (unsigned char *)buf ) == 1 ) // VBR�̴�. + if ( __AvGetXingHeader( &data, (unsigned char *)buf ) == 1 ) // VBR. { if (data.sampRate == 0 || data.bytes == 0 || data.frames == 0) { debug_error ("invalid Xing header\n"); @@ -631,7 +662,7 @@ __AvParseVBRIHeader( AvFileContentInfo* pInfo, unsigned char* buf ) AvVBRIHeadData data; memset( &data, 0x00, sizeof(AvVBRIHeadData) ); - // 1. Xing Header üũ + // 1. Xing Header if((pInfo->mpegVersion == AV_MPEG_VER_1) && (pInfo->channels == 2)) { if( buf[36] != 'V' ) return false; @@ -655,11 +686,11 @@ __AvParseVBRIHeader( AvFileContentInfo* pInfo, unsigned char* buf ) if( buf[39] != 'I' ) return false; } - // 2. TOC�� ����ұ� + // 2. TOC if ( pInfo->pToc ) data.toc = (unsigned char*)(pInfo->pToc); - if ( __AvGetVBRIHeader( &data, (unsigned char*)buf ) == 1 ) // VBR�̴�. + if ( __AvGetVBRIHeader( &data, (unsigned char*)buf ) == 1 ) // VBR. { if (data.sampRate == 0 || data.bytes == 0 || data.frames == 0) { debug_error ("invalid Vbri header\n"); diff --git a/packaging/libmm-fileinfo.spec b/packaging/libmm-fileinfo.spec index e18ccd3..bf04cdc 100755 --- a/packaging/libmm-fileinfo.spec +++ b/packaging/libmm-fileinfo.spec @@ -1,7 +1,7 @@ Name: libmm-fileinfo Summary: Media Fileinfo Version: 0.6.0 -Release: 18 +Release: 19 Group: System/Libraries License: Apache License, Version 2.0 Source0: %{name}-%{version}.tar.gz diff --git a/tests/mm_file_test.c b/tests/mm_file_test.c index a79c9e8..bc192c7 100755 --- a/tests/mm_file_test.c +++ b/tests/mm_file_test.c @@ -139,7 +139,7 @@ do{ \ size = ftell(fp); \ fseek (fp, 0, SEEK_SET); \ data = malloc (size); \ - fread (data, size, sizeof(char), fp); \ + if (fread (data, size, sizeof(char), fp) != size) { printf("fread error\n"); } \ fclose (fp); \ printf("file size = %d\n", size ); \ } \