OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 SERVICES_MEDIA_FRAMEWORK_PACKET_H_ | 5 #ifndef SERVICES_MEDIA_FRAMEWORK_PACKET_H_ |
6 #define SERVICES_MEDIA_FRAMEWORK_PACKET_H_ | 6 #define SERVICES_MEDIA_FRAMEWORK_PACKET_H_ |
7 | 7 |
8 #include <limits> | 8 #include <limits> |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 // no special behavior. | 29 // no special behavior. |
30 // TODO(dalesat): Revisit this definition: | 30 // TODO(dalesat): Revisit this definition: |
31 // 1) We probably need an extensible way to add metadata to packets. | 31 // 1) We probably need an extensible way to add metadata to packets. |
32 // 2) The relationship to the allocator could be clearer. | 32 // 2) The relationship to the allocator could be clearer. |
33 class Packet { | 33 class Packet { |
34 public: | 34 public: |
35 static const int64_t kUnknownPts = std::numeric_limits<int64_t>::min(); | 35 static const int64_t kUnknownPts = std::numeric_limits<int64_t>::min(); |
36 | 36 |
37 // Creates a packet. If size is 0, payload must be nullptr and vice-versa. | 37 // Creates a packet. If size is 0, payload must be nullptr and vice-versa. |
38 // If payload is not nullptr, an allocator must be provided. | 38 // If payload is not nullptr, an allocator must be provided. |
39 static PacketPtr Create( | 39 static PacketPtr Create(int64_t pts, |
40 int64_t pts, | 40 bool end_of_stream, |
41 bool end_of_stream, | 41 size_t size, |
42 size_t size, | 42 void* payload, |
43 void* payload, | 43 PayloadAllocator* allocator); |
44 PayloadAllocator* allocator); | |
45 | 44 |
46 // Creates a packet. If size is 0, payload must be nullptr and vice-versa. | 45 // Creates a packet. If size is 0, payload must be nullptr and vice-versa. |
47 // No allocator is provided, and the payload will not be released when the | 46 // No allocator is provided, and the payload will not be released when the |
48 // packet is released. | 47 // packet is released. |
49 static PacketPtr CreateNoAllocator( | 48 static PacketPtr CreateNoAllocator(int64_t pts, |
50 int64_t pts, | 49 bool end_of_stream, |
51 bool end_of_stream, | 50 size_t size, |
52 size_t size, | 51 void* payload); |
53 void* payload); | |
54 | 52 |
55 // Creates an end-of-stream packet with no payload. | 53 // Creates an end-of-stream packet with no payload. |
56 static PacketPtr CreateEndOfStream(int64_t pts); | 54 static PacketPtr CreateEndOfStream(int64_t pts); |
57 | 55 |
58 int64_t pts() const { return pts_; } | 56 int64_t pts() const { return pts_; } |
59 | 57 |
60 bool end_of_stream() const { return end_of_stream_; } | 58 bool end_of_stream() const { return end_of_stream_; } |
61 | 59 |
62 size_t size() const { return size_; } | 60 size_t size() const { return size_; } |
63 | 61 |
64 void* payload() const { return payload_; } | 62 void* payload() const { return payload_; } |
65 | 63 |
66 protected: | 64 protected: |
67 Packet( | 65 Packet(int64_t pts, bool end_of_stream, size_t size, void* payload); |
68 int64_t pts, | |
69 bool end_of_stream, | |
70 size_t size, | |
71 void* payload); | |
72 | 66 |
73 virtual ~Packet() {} | 67 virtual ~Packet() {} |
74 | 68 |
75 virtual void Release() = 0; | 69 virtual void Release() = 0; |
76 | 70 |
77 private: | 71 private: |
78 int64_t pts_; | 72 int64_t pts_; |
79 bool end_of_stream_; | 73 bool end_of_stream_; |
80 size_t size_; | 74 size_t size_; |
81 void* payload_; | 75 void* payload_; |
82 | 76 |
83 friend PacketDeleter; | 77 friend PacketDeleter; |
84 }; | 78 }; |
85 | 79 |
86 inline void PacketDeleter::operator()(Packet* ptr) const { | 80 inline void PacketDeleter::operator()(Packet* ptr) const { |
87 DCHECK(ptr); | 81 DCHECK(ptr); |
88 ptr->Release(); | 82 ptr->Release(); |
89 } | 83 } |
90 | 84 |
91 } // namespace media | 85 } // namespace media |
92 } // namespace mojo | 86 } // namespace mojo |
93 | 87 |
94 #endif // SERVICES_MEDIA_FRAMEWORK_PACKET_H_ | 88 #endif // SERVICES_MEDIA_FRAMEWORK_PACKET_H_ |
OLD | NEW |