2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FMedia_FfmpegUtil.cpp
20 * @brief This is the implementation file for the FMedia::_FfmpegUtil.
22 * This file contains the implementations of the FMedia::_FfmpegUtil.
25 #include <FBaseObject.h>
26 #include <FMediaTypes.h>
27 #include <FMediaAudioTypes.h>
28 #include "FMedia_Ffmpeg.h"
29 #include "FMedia_FfmpegUtil.h"
31 using namespace Tizen::Base;
33 namespace Tizen { namespace Media
39 Tizen::Media::CodecType codecType;
42 static const _CodecTypeIdMap _CODEC_ID_MAP[] = {
43 { CODEC_ID_AAC, CODEC_AAC},
44 { CODEC_ID_MP3, CODEC_MP3},
45 { CODEC_ID_AMR_NB, CODEC_AMR_NB},
46 { CODEC_ID_H264, CODEC_H264},
47 { CODEC_ID_H263, CODEC_H263},
48 { CODEC_ID_MPEG4, CODEC_MPEG4}
53 AVSampleFormat avSampleFormat;
54 Tizen::Media::AudioSampleType audioSampleType;
57 static const _SampleFormatMap _SAMPLE_FORMAT_MAP[] = {
58 { AV_SAMPLE_FMT_U8, AUDIO_TYPE_PCM_U8},
59 { AV_SAMPLE_FMT_S16, AUDIO_TYPE_PCM_S16_LE}
62 Tizen::Media::CodecType
63 _FfmpegUtil::ToCodecType(CodecID codecId)
65 for (unsigned int i = 0; i < sizeof(_CODEC_ID_MAP)/sizeof(_CODEC_ID_MAP[0]); i++)
67 if (codecId == _CODEC_ID_MAP[i].codecId)
69 return _CODEC_ID_MAP[i].codecType;
76 _FfmpegUtil::ToCodecID(Tizen::Media::CodecType codecType)
78 for (unsigned int i = 0; i < sizeof(_CODEC_ID_MAP)/sizeof(_CODEC_ID_MAP[0]); i++)
80 if (codecType == _CODEC_ID_MAP[i].codecType)
82 return _CODEC_ID_MAP[i].codecId;
89 _FfmpegUtil::ToAudioChannelType(int channels)
91 AudioChannelType channelType = AUDIO_CHANNEL_TYPE_NONE;
96 channelType = AUDIO_CHANNEL_TYPE_MONO;
100 channelType = AUDIO_CHANNEL_TYPE_STEREO;
111 _FfmpegUtil::ToAudioSampleType(AVSampleFormat sampleFormat)
113 for (unsigned int i = 0; i < sizeof(_SAMPLE_FORMAT_MAP)/sizeof(_SAMPLE_FORMAT_MAP[0]); i++)
115 if (sampleFormat == _SAMPLE_FORMAT_MAP[i].avSampleFormat)
117 return _SAMPLE_FORMAT_MAP[i].audioSampleType;
120 return AUDIO_TYPE_NONE;
124 _FfmpegUtil::ToAvSampleFormat(AudioSampleType sampleType)
126 for (unsigned int i = 0; i < sizeof(_SAMPLE_FORMAT_MAP)/sizeof(_SAMPLE_FORMAT_MAP[0]); i++)
128 if (sampleType == _SAMPLE_FORMAT_MAP[i].audioSampleType)
130 return _SAMPLE_FORMAT_MAP[i].avSampleFormat;
133 return AV_SAMPLE_FMT_NONE;