Tizen 2.0 Release
[framework/osp/media.git] / src / FMediaVideoFrameExtractor.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 #include <FMediaVideoFrameExtractor.h>
18 #include <FMedia_VideoFrameExtractorImpl.h>
19 #include <FBaseSysLog.h>
20
21 using namespace Tizen::Base;
22 using namespace Tizen::Graphics;
23
24 namespace Tizen { namespace Media {
25
26 VideoFrameExtractor::VideoFrameExtractor(void)
27         :__pImpl(null)
28 {
29 }
30
31 VideoFrameExtractor::~VideoFrameExtractor(void)
32 {
33
34         if (__pImpl != null)
35         {
36                 delete __pImpl;
37                 __pImpl = null;
38         }
39 }
40
41 result
42 VideoFrameExtractor::Construct(const Tizen::Base::String &filePath, MediaPixelFormat pixelFormat)
43 {
44         result r = E_SUCCESS;
45         _VideoFrameExtractorImpl* pVideoFrameExtractorImpl = null;
46
47         SysAssertf(__pImpl == null,
48                 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
49
50         SysTryReturn(NID_MEDIA, !filePath.IsEmpty(), E_FILE_NOT_FOUND, E_FILE_NOT_FOUND,
51                 "[%s] Propagating.", GetErrorMessage(E_FILE_NOT_FOUND));
52
53         pVideoFrameExtractorImpl = new (std::nothrow) _VideoFrameExtractorImpl();
54         SysTryReturnResult(NID_MEDIA, pVideoFrameExtractorImpl != null, E_OUT_OF_MEMORY, "Create instance failed.");
55
56         r = pVideoFrameExtractorImpl->Construct(filePath, pixelFormat);
57         SysTryCatch(NID_MEDIA, r == E_SUCCESS, , GetLastResult(),
58                         "[%s] Failed to Construct pVideoFrameExtractorImpl.", GetErrorMessage(GetLastResult()));
59
60         __pImpl = pVideoFrameExtractorImpl;
61
62         return E_SUCCESS;
63
64 CATCH:
65         delete pVideoFrameExtractorImpl;
66         pVideoFrameExtractorImpl = null;
67
68         return r;
69 }
70
71
72 int
73 VideoFrameExtractor::GetWidth(void) const
74 {
75         SysAssertf(__pImpl != null,
76                 "Not yet constructed. Construct() should be called before use.");
77
78         return __pImpl->GetWidth();
79 }
80
81 int
82 VideoFrameExtractor::GetHeight(void) const
83 {
84         SysAssertf(__pImpl != null,
85                 "Not yet constructed. Construct() should be called before use.");
86
87         return __pImpl->GetHeight();
88
89 }
90
91 long
92 VideoFrameExtractor::GetDuration(void) const
93 {
94         SysAssertf(__pImpl != null,
95                 "Not yet constructed. Construct() should be called before use.");
96
97         return __pImpl->GetDuration();
98 }
99
100 ImageBuffer*
101 VideoFrameExtractor::GetFrameN(long timestamp)
102 {
103         SysAssertf(__pImpl != null,
104                 "Not yet constructed. Construct() should be called before use.");
105
106         return  __pImpl->GetFrameN(timestamp);
107
108 }
109
110 ImageBuffer*
111 VideoFrameExtractor::GetFrameN(const Tizen::Base::String& path, MediaPixelFormat pixelFormat, long timestamp )
112 {
113         return _VideoFrameExtractorImpl::GetFrameN(path, pixelFormat, timestamp);
114
115 }
116
117 }} // Tizen::Media
118