Merge "seek expection handling bug" into tizen_2.2
[platform/framework/native/media.git] / src / FMedia_CameraBuffer.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_CameraBuffer.cpp
20  * @brief                       This file contains the implementation of the %_CameraBuffer class.
21  *
22  */
23
24 #include <FBaseSysLog.h>
25 #include "FMedia_CameraBuffer.h"
26
27 using namespace Tizen::Base;
28 using namespace Tizen::Graphics;
29
30 namespace Tizen { namespace Media
31 {
32
33 _CameraBuffer::_CameraBuffer(void)
34         : __bufferType(_CAMERA_BUFFER_NONE)
35         , __pixelFormat(MEDIA_PIXEL_FORMAT_NONE)
36         , __width(0)
37         , __height(0)
38         , __codec(CODEC_NONE)
39         , __hasHeader(false)
40 {
41 }
42
43 _CameraBuffer::~_CameraBuffer(void)
44 {
45 }
46
47 result
48 _CameraBuffer::Construct(int capacity, _CameraBufferType bufferType, MediaPixelFormat pixelFormat, int width, int height)
49 {
50         result r = E_SUCCESS;
51 //      SysLog(NID_MEDIA, "Enter. capacity:%d, bufferType:%d, pixelFormat:%d, width:%d, height:%d", capacity, bufferType, pixelFormat, width, height);
52         SysTryReturn(NID_MEDIA, capacity>0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The capacity[%d] is invalid.", capacity);
53         SysTryReturn(NID_MEDIA, bufferType >= _CAMERA_BUFFER_PREVIEW && bufferType <= _CAMERA_BUFFER_CAPTURE, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The bufferType(%d)  is invalid.", bufferType);
54         SysTryReturn(NID_MEDIA, pixelFormat >= MEDIA_PIXEL_FORMAT_NONE, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The pixelFormat(%d)  is invalid.", pixelFormat);
55
56         r = ByteBuffer::Construct(capacity);
57         SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
58
59         __bufferType = bufferType;
60         __pixelFormat = pixelFormat;
61         __width = width;
62         __height = height;
63
64         return r;
65
66 CATCH:
67         return r;
68 }
69
70 result
71 _CameraBuffer::Construct(int capacity, _CameraBufferType bufferType, CodecType codec, bool hasHeader, int width, int height)
72 {
73         result r = E_SUCCESS;
74 //      SysLog(NID_MEDIA, "Capacity:%d, bufferType:%d, codec:0x%x, width:%d, height:%d", capacity, bufferType, codec, width, height);
75         SysTryReturn(NID_MEDIA, capacity>0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The capacity[%d] is invalid.", capacity);
76         SysTryReturn(NID_MEDIA, bufferType >= _CAMERA_BUFFER_PREVIEW && bufferType <= _CAMERA_BUFFER_CAPTURE, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The bufferType(%d)  is invalid.", bufferType);
77         SysTryReturn(NID_MEDIA, codec >= CODEC_NONE && codec < CODEC_MAX
78                 , E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The codec(0x%x)        is invalid.", codec);
79
80         r = ByteBuffer::Construct(capacity);
81         SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
82
83         __bufferType = bufferType;
84         __width = width;
85         __height = height;
86         __codec = codec;
87         __hasHeader = hasHeader;
88
89         return r;
90
91 CATCH:
92         return r;
93 }
94
95 result
96 _CameraBuffer::Construct(const _CameraBuffer& cameraBuffer)
97 {
98         result r = E_SUCCESS;
99 //      SysLog(NID_MEDIA, "BufferType:%d, pixelFormat:%d", cameraBuffer.__bufferType, cameraBuffer.__pixelFormat);
100
101         r = ByteBuffer::Construct(cameraBuffer);
102         SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
103
104         __bufferType = cameraBuffer.__bufferType;
105         __pixelFormat = cameraBuffer.__pixelFormat;
106         __width = cameraBuffer.__width;
107         __height = cameraBuffer.__height;
108         __codec = cameraBuffer.__codec;
109         __hasHeader = cameraBuffer.__hasHeader;
110
111         return r;
112
113 CATCH:
114         return r;
115 }
116
117 MediaPixelFormat
118 _CameraBuffer::GetPixelFormat(void) const
119 {
120         return __pixelFormat;
121 }
122
123 _CameraBufferType
124 _CameraBuffer::GetBufferType(void) const
125 {
126         return __bufferType;
127 }
128
129 int
130 _CameraBuffer::GetWidth(void) const
131 {
132         return __width;
133 }
134
135 int
136 _CameraBuffer::GetHeight(void) const
137 {
138         return __height;
139 }
140
141 CodecType
142 _CameraBuffer::GetCodecType(void) const
143 {
144         return __codec;
145 }
146
147 }}   // Tizen::Media