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