Merge "seek expection handling bug" into tizen_2.2
[platform/framework/native/media.git] / src / FMedia_AudioFrameImpl.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_AudioFrameImpl.cpp
20  * @brief                This file contains the implementation of the _AudioFrameImpl class.
21  *
22  */
23
24 #include <unique_ptr.h>
25 #include <FBaseSysLog.h>
26 #include <FMediaAudioFrame.h>
27 #include <FMediaAudioTypes.h>
28 #include "FMedia_AudioFrameImpl.h"
29
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32
33 namespace Tizen { namespace Media
34 {
35 static const int _AUDIO_PLANE_COUNT = 1;
36
37 _AudioFrameImpl::_AudioFrameImpl(void)
38         : __samplingRate(0)
39         , __channel(AUDIO_CHANNEL_TYPE_NONE)
40         , __sampleType(AUDIO_TYPE_NONE)
41         , __planeCount(_AUDIO_PLANE_COUNT)
42         , __pAudioStreamBuffer(null)
43 {
44
45 }
46
47 _AudioFrameImpl::~_AudioFrameImpl(void)
48 {
49 }
50
51 result
52 _AudioFrameImpl::Initialize(byte* pStream, int size, int samplingRate, AudioChannelType channel, AudioSampleType sampleType)
53 {
54         result r = E_SUCCESS;
55
56         __pAudioStreamBuffer.reset(new (std::nothrow) Tizen::Base::ByteBuffer());
57         SysTryReturn(NID_MEDIA, __pAudioStreamBuffer.get() != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.  The object is not created.");
58
59         r = __pAudioStreamBuffer->Construct(pStream, 0, size, size);
60         SysTryReturn(NID_MEDIA, r== E_SUCCESS, r, r, "[%s] Propogating", GetErrorMessage(r));
61
62         __samplingRate = samplingRate;
63         __channel = channel;
64         __sampleType = sampleType;
65
66         return r;
67 }
68
69 int
70 _AudioFrameImpl:: GetPlaneCount(void) const
71 {
72         return __planeCount;
73 }
74
75 Tizen::Base::ByteBuffer*
76 _AudioFrameImpl::GetPlaneData(int index) const
77 {
78         SysTryReturn(NID_MEDIA, index < __planeCount, null, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index %d is out of range, plane count %d.",index, __planeCount);
79
80         return __pAudioStreamBuffer.get();
81 }
82
83 int
84 _AudioFrameImpl::GetSamplingRate(void) const
85 {
86         return __samplingRate;
87 }
88
89 AudioChannelType
90 _AudioFrameImpl::GetChannelType(void) const
91 {
92         return __channel;
93 }
94
95 AudioSampleType
96 _AudioFrameImpl::GetSampleType(void) const
97 {
98         return __sampleType;
99 }
100
101 _AudioFrameImpl*
102 _AudioFrameImpl::GetInstance(AudioFrame *pAudioFrame)
103 {
104         if ( pAudioFrame != null )
105         {
106                 return pAudioFrame->__pImpl;
107         }
108         return null;
109 }
110
111 const _AudioFrameImpl*
112 _AudioFrameImpl::GetInstance(const AudioFrame *pAudioFrame)
113 {
114         if ( pAudioFrame != null)
115         {
116                 return pAudioFrame->__pImpl;
117         }
118         return null;
119 }
120
121 }}   // Tizen::Media