CAF state bug fix
[platform/framework/native/media.git] / src / FMedia_FfmpegUtil.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file   FMedia_FfmpegUtil.cpp
20  * @brief  This is the implementation file for the FMedia::_FfmpegUtil.
21  *
22  * This file contains the implementations of the FMedia::_FfmpegUtil.
23  *
24  */
25 #include <FBaseObject.h>
26 #include <FMediaTypes.h>
27 #include <FMediaAudioTypes.h>
28 #include "FMedia_Ffmpeg.h"
29 #include "FMedia_FfmpegUtil.h"
30
31 using namespace Tizen::Base;
32
33 namespace Tizen { namespace Media
34 {
35
36 typedef struct
37 {
38         CodecID codecId;
39         Tizen::Media::CodecType codecType;
40 } _CodecTypeIdMap;
41
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}
49 };
50
51 typedef struct
52 {
53         AVSampleFormat avSampleFormat;
54         Tizen::Media::AudioSampleType audioSampleType;
55 } _SampleFormatMap;
56
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}
60 };
61
62 Tizen::Media::CodecType
63 _FfmpegUtil::ToCodecType(CodecID codecId)
64 {
65         for (unsigned int i = 0; i < sizeof(_CODEC_ID_MAP)/sizeof(_CODEC_ID_MAP[0]); i++)
66         {
67                 if (codecId == _CODEC_ID_MAP[i].codecId)
68                 {
69                         return _CODEC_ID_MAP[i].codecType;
70                 }
71         }
72         return CODEC_UNKNOWN;
73 }
74
75 CodecID
76 _FfmpegUtil::ToCodecID(Tizen::Media::CodecType codecType)
77 {
78         for (unsigned int i = 0; i < sizeof(_CODEC_ID_MAP)/sizeof(_CODEC_ID_MAP[0]); i++)
79         {
80                 if (codecType == _CODEC_ID_MAP[i].codecType)
81                 {
82                         return _CODEC_ID_MAP[i].codecId;
83                 }
84         }
85         return CODEC_ID_NONE;
86 }
87
88 AudioChannelType
89 _FfmpegUtil::ToAudioChannelType(int channels)
90 {
91         AudioChannelType channelType = AUDIO_CHANNEL_TYPE_NONE;
92
93         switch (channels)
94         {
95         case 1:
96                 channelType = AUDIO_CHANNEL_TYPE_MONO;
97         break;
98
99         case 2:
100                 channelType = AUDIO_CHANNEL_TYPE_STEREO;
101         break;
102
103         default:
104                 break;
105         }
106
107         return channelType;
108 }
109
110 AudioSampleType
111 _FfmpegUtil::ToAudioSampleType(AVSampleFormat sampleFormat)
112 {
113         for (unsigned int i = 0; i < sizeof(_SAMPLE_FORMAT_MAP)/sizeof(_SAMPLE_FORMAT_MAP[0]); i++)
114         {
115                 if (sampleFormat == _SAMPLE_FORMAT_MAP[i].avSampleFormat)
116                 {
117                         return _SAMPLE_FORMAT_MAP[i].audioSampleType;
118                 }
119         }
120         return AUDIO_TYPE_NONE;
121 }
122
123 AVSampleFormat
124 _FfmpegUtil::ToAvSampleFormat(AudioSampleType sampleType)
125 {
126         for (unsigned int i = 0; i < sizeof(_SAMPLE_FORMAT_MAP)/sizeof(_SAMPLE_FORMAT_MAP[0]); i++)
127         {
128                 if (sampleType == _SAMPLE_FORMAT_MAP[i].audioSampleType)
129                 {
130                         return _SAMPLE_FORMAT_MAP[i].avSampleFormat;
131                 }
132         }
133         return AV_SAMPLE_FMT_NONE;
134 }
135
136 }} // Tizen::Media