• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  // Copyright 2020 The Chromium Authors. All rights reserved.
2  // Use of this source code is governed by a BSD-style license that can be
3  // found in the LICENSE file.
4  
5  //#define LOG_NDEBUG 0
6  #define LOG_TAG "VideoFrame"
7  
8  #include <v4l2_codec2/components/VideoFrame.h>
9  
10  #include <C2AllocatorGralloc.h>
11  #include <log/log.h>
12  
13  namespace android {
14  
15  // static
Create(std::shared_ptr<C2GraphicBlock> block)16  std::unique_ptr<VideoFrame> VideoFrame::Create(std::shared_ptr<C2GraphicBlock> block) {
17      if (!block) return nullptr;
18  
19      std::vector<int> fds;
20      const C2Handle* const handle = block->handle();
21      for (int i = 0; i < handle->numFds; i++) {
22          fds.emplace_back(handle->data[i]);
23      }
24  
25      return std::unique_ptr<VideoFrame>(new VideoFrame(std::move(block), std::move(fds)));
26  }
27  
VideoFrame(std::shared_ptr<C2GraphicBlock> block,std::vector<int> fds)28  VideoFrame::VideoFrame(std::shared_ptr<C2GraphicBlock> block, std::vector<int> fds)
29        : mGraphicBlock(std::move(block)), mFds(fds) {}
30  
31  VideoFrame::~VideoFrame() = default;
32  
getFDs() const33  const std::vector<int>& VideoFrame::getFDs() const {
34      return mFds;
35  }
36  
setVisibleRect(const media::Rect & visibleRect)37  void VideoFrame::setVisibleRect(const media::Rect& visibleRect) {
38      mVisibleRect = visibleRect;
39  }
40  
getVisibleRect() const41  const media::Rect& VideoFrame::getVisibleRect() const {
42      return mVisibleRect;
43  }
44  
setBitstreamId(int32_t bitstreamId)45  void VideoFrame::setBitstreamId(int32_t bitstreamId) {
46      mBitstreamId = bitstreamId;
47  }
48  
getBitstreamId() const49  int32_t VideoFrame::getBitstreamId() const {
50      return mBitstreamId;
51  }
52  
getGraphicBlock()53  C2ConstGraphicBlock VideoFrame::getGraphicBlock() {
54      return mGraphicBlock->share(C2Rect(mVisibleRect.width(), mVisibleRect.height()), C2Fence());
55  }
56  
57  }  // namespace android
58