• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "video_capture_sf_yuv_impl.h"
17 #include "media_log.h"
18 #include "media_errors.h"
19 #include "scope_guard.h"
20 
21 namespace {
22     constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "VideoCaptureSfYuvmpl"};
23 }
24 
25 namespace OHOS {
26 namespace Media {
VideoCaptureSfYuvImpl()27 VideoCaptureSfYuvImpl::VideoCaptureSfYuvImpl()
28 {
29 }
30 
~VideoCaptureSfYuvImpl()31 VideoCaptureSfYuvImpl::~VideoCaptureSfYuvImpl()
32 {
33 }
34 
DoGetCodecBuffer()35 std::shared_ptr<EsAvcCodecBuffer> VideoCaptureSfYuvImpl::DoGetCodecBuffer()
36 {
37     return nullptr;
38 }
39 
DoGetFrameBuffer()40 std::shared_ptr<VideoFrameBuffer> VideoCaptureSfYuvImpl::DoGetFrameBuffer()
41 {
42     MEDIA_LOGD("enter yuv DoGetFrameBuffer");
43 
44     uint32_t bufferSize = static_cast<uint32_t>(dataSize_); // yuv size after encode
45     MEDIA_LOGI("input buffersize is %{public}d", bufferSize);
46 
47     ON_SCOPE_EXIT(0) { (void)dataConSurface_->ReleaseBuffer(surfaceBuffer_, fence_); };
48 
49     gpointer buffer = surfaceBuffer_->GetVirAddr();
50     CHECK_AND_RETURN_RET_LOG(buffer != nullptr, nullptr, "surface buffer address is invalid");
51 
52     GstBuffer *gstBuffer = gst_buffer_new_allocate(nullptr, bufferSize, nullptr);
53     CHECK_AND_RETURN_RET_LOG(gstBuffer != nullptr, nullptr, "no memory");
54 
55     ON_SCOPE_EXIT(1) { gst_buffer_unref(gstBuffer); };
56 
57     gsize size = gst_buffer_fill(gstBuffer, 0, (char *)buffer, bufferSize);
58     CHECK_AND_RETURN_RET_LOG(size == static_cast<gsize>(bufferSize), nullptr, "unknown error during gst_buffer_fill");
59 
60     std::shared_ptr<VideoFrameBuffer> frameBuffer = std::make_shared<VideoFrameBuffer>();
61     frameBuffer->keyFrameFlag = 0;
62     frameBuffer->timeStamp = static_cast<uint64_t>(pts_); // yuv timestamp from camera
63     frameBuffer->gstBuffer = gstBuffer;
64     frameBuffer->size = static_cast<uint64_t>(bufferSize);
65     frameBuffer->pixelFormat = pixelFormat_;
66 
67     CANCEL_SCOPE_EXIT_GUARD(1);
68     return frameBuffer;
69 }
70 } // namespace Media
71 } // namespace OHOS
72