lin
2025-04-25 6a7002bcc41716f11f4ca7eb68ebd06c18fdd5e8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Note: ported from Chromium commit head: 39a7f93
 
#ifndef MEDIA_BASE_BITSTREAM_BUFFER_H_
#define MEDIA_BASE_BITSTREAM_BUFFER_H_
 
#include <stddef.h>
#include <stdint.h>
 
#include "base/macros.h"
#include "base/memory/shared_memory.h"
#include "base/time/time.h"
 
namespace media {
 
// Indicates an invalid or missing timestamp.
constexpr base::TimeDelta kNoTimestamp =
    base::TimeDelta::FromMicroseconds(std::numeric_limits<int64_t>::min());
 
// Class for passing bitstream buffers around.  Does not take ownership of the
// data.  This is the media-namespace equivalent of PP_VideoBitstreamBuffer_Dev.
class BitstreamBuffer {
 public:
  BitstreamBuffer();
 
  // Constructs a new BitstreamBuffer. The content of the bitstream is located
  // at |offset| bytes away from the start of the shared memory and the payload
  // is |size| bytes. When not provided, the default value for |offset| is 0.
  // |presentation_timestamp| is when the decoded frame should be displayed.
  // When not provided, |presentation_timestamp| will be
  // |media::kNoTimestamp|.
  BitstreamBuffer(int32_t id,
                  base::SharedMemoryHandle handle,
                  size_t size,
                  off_t offset = 0,
                  base::TimeDelta presentation_timestamp = kNoTimestamp);
 
  BitstreamBuffer(const BitstreamBuffer& other);
 
  ~BitstreamBuffer();
 
  int32_t id() const { return id_; }
  base::SharedMemoryHandle handle() const { return handle_; }
 
  // The number of bytes of the actual bitstream data. It is the size of the
  // content instead of the whole shared memory.
  size_t size() const { return size_; }
 
  // The offset to the start of actual bitstream data in the shared memory.
  off_t offset() const { return offset_; }
 
  // The timestamp is only valid if it's not equal to |media::kNoTimestamp|.
  base::TimeDelta presentation_timestamp() const {
    return presentation_timestamp_;
  }
 
  void set_handle(const base::SharedMemoryHandle& handle) { handle_ = handle; }
 
 private:
  int32_t id_;
  base::SharedMemoryHandle handle_;
  size_t size_;
  off_t offset_;
 
  // This is only set when necessary. For example, AndroidVideoDecodeAccelerator
  // needs the timestamp because the underlying decoder may require it to
  // determine the output order.
  base::TimeDelta presentation_timestamp_;
 
  // Allow compiler-generated copy & assign constructors.
};
 
}  // namespace media
 
#endif  // MEDIA_BASE_BITSTREAM_BUFFER_H_