tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

encoded_image.cc (3162B)


      1 /*
      2 *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
      3 *
      4 *  Use of this source code is governed by a BSD-style license
      5 *  that can be found in the LICENSE file in the root of the source
      6 *  tree. An additional intellectual property rights grant can be found
      7 *  in the file PATENTS.  All contributing project authors may
      8 *  be found in the AUTHORS file in the root of the source tree.
      9 */
     10 
     11 #include "api/video/encoded_image.h"
     12 
     13 #include <cstdint>
     14 #include <cstdlib>
     15 #include <optional>
     16 #include <utility>
     17 
     18 #include "api/make_ref_counted.h"
     19 #include "api/scoped_refptr.h"
     20 #include "api/units/timestamp.h"
     21 #include "rtc_base/buffer.h"
     22 #include "rtc_base/checks.h"
     23 
     24 namespace webrtc {
     25 
     26 EncodedImageBuffer::EncodedImageBuffer(size_t size) : buffer_(size) {}
     27 
     28 EncodedImageBuffer::EncodedImageBuffer(const uint8_t* data, size_t size)
     29    : buffer_(data, size) {}
     30 
     31 EncodedImageBuffer::EncodedImageBuffer(Buffer buffer)
     32    : buffer_(std::move(buffer)) {}
     33 
     34 // static
     35 scoped_refptr<EncodedImageBuffer> EncodedImageBuffer::Create(size_t size) {
     36  return make_ref_counted<EncodedImageBuffer>(size);
     37 }
     38 // static
     39 scoped_refptr<EncodedImageBuffer> EncodedImageBuffer::Create(
     40    const uint8_t* data,
     41    size_t size) {
     42  return make_ref_counted<EncodedImageBuffer>(data, size);
     43 }
     44 // static
     45 scoped_refptr<EncodedImageBuffer> EncodedImageBuffer::Create(Buffer buffer) {
     46  return make_ref_counted<EncodedImageBuffer>(std::move(buffer));
     47 }
     48 
     49 const uint8_t* EncodedImageBuffer::data() const {
     50  return buffer_.data();
     51 }
     52 uint8_t* EncodedImageBuffer::data() {
     53  return buffer_.data();
     54 }
     55 size_t EncodedImageBuffer::size() const {
     56  return buffer_.size();
     57 }
     58 
     59 void EncodedImageBuffer::Realloc(size_t size) {
     60  buffer_.SetSize(size);
     61 }
     62 
     63 EncodedImage::EncodedImage() = default;
     64 
     65 EncodedImage::EncodedImage(EncodedImage&&) = default;
     66 EncodedImage::EncodedImage(const EncodedImage&) = default;
     67 
     68 EncodedImage::~EncodedImage() = default;
     69 
     70 EncodedImage& EncodedImage::operator=(EncodedImage&&) = default;
     71 EncodedImage& EncodedImage::operator=(const EncodedImage&) = default;
     72 
     73 void EncodedImage::SetEncodeTime(int64_t encode_start_ms,
     74                                 int64_t encode_finish_ms) {
     75  timing_.encode_start_ms = encode_start_ms;
     76  timing_.encode_finish_ms = encode_finish_ms;
     77 }
     78 
     79 Timestamp EncodedImage::CaptureTime() const {
     80  return capture_time_ms_ > 0 ? Timestamp::Millis(capture_time_ms_)
     81                              : Timestamp::MinusInfinity();
     82 }
     83 
     84 std::optional<size_t> EncodedImage::SpatialLayerFrameSize(
     85    int spatial_index) const {
     86  RTC_DCHECK_GE(spatial_index, 0);
     87  RTC_DCHECK_LE(spatial_index, spatial_index_.value_or(0));
     88 
     89  auto it = spatial_layer_frame_size_bytes_.find(spatial_index);
     90  if (it == spatial_layer_frame_size_bytes_.end()) {
     91    return std::nullopt;
     92  }
     93 
     94  return it->second;
     95 }
     96 
     97 void EncodedImage::SetSpatialLayerFrameSize(int spatial_index,
     98                                            size_t size_bytes) {
     99  RTC_DCHECK_GE(spatial_index, 0);
    100  RTC_DCHECK_LE(spatial_index, spatial_index_.value_or(0));
    101  RTC_DCHECK_GE(size_bytes, 0);
    102  spatial_layer_frame_size_bytes_[spatial_index] = size_bytes;
    103 }
    104 
    105 }  // namespace webrtc