CAF state bug fix
[platform/framework/native/media.git] / src / FMedia_VideoStreamCoordinator.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_VideoStreamCoordinator.cpp
20  * @brief                       This file contains the video stream processing.
21  *
22  */
23 #include <unique_ptr.h>
24 #include <FBaseSysLog.h>
25 #include <FMediaVideoFrame.h>
26 #include "FMedia_VideoFrameImpl.h"
27 #include "FMedia_VideoStreamCoordinator.h"
28
29 using namespace Tizen::Base;
30 using namespace Tizen::Base::Collection;
31
32 namespace Tizen { namespace Media
33 {
34
35 _VideoStreamCoordinator::_VideoStreamCoordinator(void)
36 : __pStreamFilterList(null, _ListPtrUtil::remover)
37 {
38
39 }
40
41 _VideoStreamCoordinator::~_VideoStreamCoordinator(void)
42 {
43
44 }
45
46 result
47 _VideoStreamCoordinator::Construct(void)
48 {
49         result r = E_SUCCESS;
50
51         __pStreamFilterList.reset(new (std::nothrow) ArrayListT<IVideoStreamFilter*>);
52         SysTryReturn(NID_MEDIA, __pStreamFilterList.get() != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.  The object is not created.");
53
54         r = __pStreamFilterList->Construct();
55         SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
56
57         return r;
58 }
59
60 result
61 _VideoStreamCoordinator::ProcessVideoStreamData(MediaPixelFormat format, int width, int height, int planeCount, byte* data[], int size[], VideoPlaneType planeType[])
62 {
63         result r = E_SUCCESS;
64
65         VideoFrame videoFrame;
66         r = videoFrame.Construct();
67         SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating", GetErrorMessage(r));
68
69         _VideoFrameImpl* pVideoFrameImpl = _VideoFrameImpl::GetInstance(&videoFrame);
70         SysTryReturn(NID_MEDIA, pVideoFrameImpl != null, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The implementation object is not found.");
71
72         r = pVideoFrameImpl->Initialize(format, width, height, planeCount, data, size, planeType);
73         SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating", GetErrorMessage(r));
74
75         std::unique_ptr <IEnumeratorT<IVideoStreamFilter*> > pEnum (__pStreamFilterList->GetEnumeratorN());
76         SysTryReturn(NID_MEDIA, pEnum.get() != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.  The object is not created.");
77
78         while (pEnum->MoveNext() == E_SUCCESS)
79         {
80                 IVideoStreamFilter* pFilter = null;
81                 r = pEnum->GetCurrent(pFilter);
82                 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating", GetErrorMessage(r));
83
84                 pFilter->ProcessVideoStream(videoFrame);
85         }
86
87         return r;
88 }
89
90 result
91 _VideoStreamCoordinator::AddVideoStreamFilter(IVideoStreamFilter& filter)
92 {
93         SysTryReturn(NID_MEDIA, __pStreamFilterList->Contains(&filter) != true, E_OBJ_ALREADY_EXIST, E_OBJ_ALREADY_EXIST, "[E_OBJ_ALREADY_EXIST] The filter already exists.");
94
95         result r = E_SUCCESS;
96         r = __pStreamFilterList->Add(&filter);
97         SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating", GetErrorMessage(r));
98
99         return r;
100 }
101
102 result
103 _VideoStreamCoordinator::RemoveVideoStreamFilter(IVideoStreamFilter& filter)
104 {
105         result r = E_SUCCESS;
106
107         r = __pStreamFilterList->Remove(&filter);
108         SysTryReturn(NID_MEDIA, r== E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
109
110         return r;
111 }
112
113 int
114 _VideoStreamCoordinator::GetFilterListCount(void) const
115 {
116         return __pStreamFilterList->GetCount();
117 }
118
119 }}
120