OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_BASE_BITSTREAM_BUFFER_H_ | 5 #ifndef MEDIA_BASE_BITSTREAM_BUFFER_H_ |
6 #define MEDIA_BASE_BITSTREAM_BUFFER_H_ | 6 #define MEDIA_BASE_BITSTREAM_BUFFER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/shared_memory.h" | 12 #include "base/memory/shared_memory.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "ipc/ipc_param_traits.h" | 14 #include "ipc/ipc_param_traits.h" |
15 #include "media/base/decrypt_config.h" | 15 #include "media/base/decrypt_config.h" |
16 #include "media/base/media_export.h" | 16 #include "media/base/media_export.h" |
17 #include "media/base/timestamp_constants.h" | 17 #include "media/base/timestamp_constants.h" |
18 | 18 |
19 namespace media { | 19 namespace media { |
20 | 20 |
21 // Class for passing bitstream buffers around. Does not take ownership of the | 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. | 22 // data. This is the media-namespace equivalent of PP_VideoBitstreamBuffer_Dev. |
23 class MEDIA_EXPORT BitstreamBuffer { | 23 class MEDIA_EXPORT BitstreamBuffer { |
24 public: | 24 public: |
25 BitstreamBuffer(); | 25 BitstreamBuffer(); |
26 | 26 |
27 BitstreamBuffer(int32_t id, base::SharedMemoryHandle handle, size_t size); | 27 // Constructs a new BitstreamBuffer. The content of the bitstream is located |
28 | 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()|. |
29 BitstreamBuffer(int32_t id, | 33 BitstreamBuffer(int32_t id, |
30 base::SharedMemoryHandle handle, | 34 base::SharedMemoryHandle handle, |
31 size_t size, | 35 size_t size, |
32 base::TimeDelta presentation_timestamp); | 36 off_t offset = 0, |
| 37 base::TimeDelta presentation_timestamp = kNoTimestamp()); |
33 | 38 |
34 BitstreamBuffer(const BitstreamBuffer& other); | 39 BitstreamBuffer(const BitstreamBuffer& other); |
35 | 40 |
36 ~BitstreamBuffer(); | 41 ~BitstreamBuffer(); |
37 | 42 |
38 void SetDecryptConfig(const DecryptConfig& decrypt_config); | 43 void SetDecryptConfig(const DecryptConfig& decrypt_config); |
39 | 44 |
40 int32_t id() const { return id_; } | 45 int32_t id() const { return id_; } |
41 base::SharedMemoryHandle handle() const { return handle_; } | 46 base::SharedMemoryHandle handle() const { return handle_; } |
| 47 |
| 48 // The number of bytes of the actual bitstream data. It is the size of the |
| 49 // content instead of the whole shared memory. |
42 size_t size() const { return size_; } | 50 size_t size() const { return size_; } |
43 | 51 |
44 void set_handle(const base::SharedMemoryHandle& handle) { handle_ = handle; } | 52 // The offset to the start of actual bitstream data in the shared memory. |
| 53 off_t offset() const { return offset_; } |
45 | 54 |
46 // The timestamp is only valid if it's not equal to |media::kNoTimestamp()|. | 55 // The timestamp is only valid if it's not equal to |media::kNoTimestamp()|. |
47 base::TimeDelta presentation_timestamp() const { | 56 base::TimeDelta presentation_timestamp() const { |
48 return presentation_timestamp_; | 57 return presentation_timestamp_; |
49 } | 58 } |
50 | 59 |
| 60 void set_handle(const base::SharedMemoryHandle& handle) { handle_ = handle; } |
| 61 |
51 // The following methods come from DecryptConfig. | 62 // The following methods come from DecryptConfig. |
52 | 63 |
53 const std::string& key_id() const { return key_id_; } | 64 const std::string& key_id() const { return key_id_; } |
54 const std::string& iv() const { return iv_; } | 65 const std::string& iv() const { return iv_; } |
55 const std::vector<SubsampleEntry>& subsamples() const { return subsamples_; } | 66 const std::vector<SubsampleEntry>& subsamples() const { return subsamples_; } |
56 | 67 |
57 private: | 68 private: |
58 int32_t id_; | 69 int32_t id_; |
59 base::SharedMemoryHandle handle_; | 70 base::SharedMemoryHandle handle_; |
60 size_t size_; | 71 size_t size_; |
| 72 off_t offset_; |
61 | 73 |
62 // This is only set when necessary. For example, AndroidVideoDecodeAccelerator | 74 // This is only set when necessary. For example, AndroidVideoDecodeAccelerator |
63 // needs the timestamp because the underlying decoder may require it to | 75 // needs the timestamp because the underlying decoder may require it to |
64 // determine the output order. | 76 // determine the output order. |
65 base::TimeDelta presentation_timestamp_; | 77 base::TimeDelta presentation_timestamp_; |
66 | 78 |
67 // The following fields come from DecryptConfig. | 79 // The following fields come from DecryptConfig. |
68 // TODO(timav): Try to DISALLOW_COPY_AND_ASSIGN and include these params as | 80 // TODO(timav): Try to DISALLOW_COPY_AND_ASSIGN and include these params as |
69 // scoped_ptr<DecryptConfig> or explain why copy & assign is needed. | 81 // scoped_ptr<DecryptConfig> or explain why copy & assign is needed. |
70 | 82 |
71 std::string key_id_; // key ID. | 83 std::string key_id_; // key ID. |
72 std::string iv_; // initialization vector | 84 std::string iv_; // initialization vector |
73 std::vector<SubsampleEntry> subsamples_; // clear/cypher sizes | 85 std::vector<SubsampleEntry> subsamples_; // clear/cypher sizes |
74 | 86 |
75 friend struct IPC::ParamTraits<media::BitstreamBuffer>; | 87 friend struct IPC::ParamTraits<media::BitstreamBuffer>; |
76 | 88 |
77 // Allow compiler-generated copy & assign constructors. | 89 // Allow compiler-generated copy & assign constructors. |
78 }; | 90 }; |
79 | 91 |
80 } // namespace media | 92 } // namespace media |
81 | 93 |
82 #endif // MEDIA_BASE_BITSTREAM_BUFFER_H_ | 94 #endif // MEDIA_BASE_BITSTREAM_BUFFER_H_ |
OLD | NEW |