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 <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "services/media/framework/allocator.h" | 11 #include "services/media/framework/payload_allocator.h" |
12 #include "services/media/framework/ptr.h" | |
13 | 12 |
14 namespace mojo { | 13 namespace mojo { |
15 namespace media { | 14 namespace media { |
16 | 15 |
17 class Packet; | 16 class Packet; |
18 | 17 |
19 // Used for PacketPtr. | 18 // Used for PacketPtr. |
20 struct PacketDeleter { | 19 struct PacketDeleter { |
21 void operator()(Packet* ptr) const; | 20 void operator()(Packet* ptr) const; |
22 }; | 21 }; |
23 | 22 |
24 // Unique pointer for packets. | 23 // Unique pointer for packets. |
25 typedef UniquePtr<Packet, PacketDeleter> PacketPtr; | 24 typedef std::unique_ptr<Packet, PacketDeleter> PacketPtr; |
26 | 25 |
27 // Media packet abstract base class. Subclasses may be defined as needed. | 26 // Media packet abstract base class. Subclasses may be defined as needed. |
28 // Packet::Create and Packet::CreateEndOfStream use an implementation with | 27 // Packet::Create and Packet::CreateEndOfStream use an implementation with |
29 // no special behavior. | 28 // no special behavior. |
30 // TODO(dalesat): Revisit this definition: | 29 // TODO(dalesat): Revisit this definition: |
31 // 1) We probably need an extensible way to add metadata to packets. | 30 // 1) We probably need an extensible way to add metadata to packets. |
32 // 2) The relationship to the allocator could be clearer. | 31 // 2) The relationship to the allocator could be clearer. |
33 class Packet { | 32 class Packet { |
34 public: | 33 public: |
35 // Creates a packet. If size is 0, payload must be nullptr and vice-versa. | 34 // Creates a packet. If size is 0, payload must be nullptr and vice-versa. |
36 // If payload is not nullptr, an allocator must be provided. | 35 // If payload is not nullptr, an allocator must be provided. |
37 static PacketPtr Create( | 36 static PacketPtr Create( |
38 int64_t presentation_time, | 37 int64_t presentation_time, |
39 uint64_t duration, | 38 uint64_t duration, |
40 bool end_of_stream, | 39 bool end_of_stream, |
41 uint64_t size, | 40 size_t size, |
42 void* payload, | 41 void* payload, |
43 Allocator* allocator); | 42 PayloadAllocator* allocator); |
44 | 43 |
45 // Creates a packet. If size is 0, payload must be nullptr and vice-versa. | 44 // Creates a packet. If size is 0, payload must be nullptr and vice-versa. |
46 // No allocator is provided, and the payload will not be released when the | 45 // No allocator is provided, and the payload will not be released when the |
47 // packet is released. | 46 // packet is released. |
48 static PacketPtr CreateNoAllocator( | 47 static PacketPtr CreateNoAllocator( |
49 int64_t presentation_time, | 48 int64_t presentation_time, |
50 uint64_t duration, | 49 uint64_t duration, |
51 bool end_of_stream, | 50 bool end_of_stream, |
52 uint64_t size, | 51 size_t size, |
53 void* payload); | 52 void* payload); |
54 | 53 |
55 // Creates an end-of-stream packet with no payload. | 54 // Creates an end-of-stream packet with no payload. |
56 static PacketPtr CreateEndOfStream(int64_t presentation_time); | 55 static PacketPtr CreateEndOfStream(int64_t presentation_time); |
57 | 56 |
58 virtual int64_t presentation_time() const = 0; | 57 virtual int64_t presentation_time() const = 0; |
59 | 58 |
60 virtual uint64_t duration() const = 0; | 59 virtual uint64_t duration() const = 0; |
61 | 60 |
62 virtual bool end_of_stream() const = 0; | 61 virtual bool end_of_stream() const = 0; |
63 | 62 |
64 virtual uint64_t size() const = 0; | 63 virtual size_t size() const = 0; |
65 | 64 |
66 virtual void* payload() const = 0; | 65 virtual void* payload() const = 0; |
67 | 66 |
68 protected: | 67 protected: |
69 virtual ~Packet() {} | 68 virtual ~Packet() {} |
70 | 69 |
71 virtual void Release() = 0; | 70 virtual void Release() = 0; |
72 | 71 |
73 friend PacketDeleter; | 72 friend PacketDeleter; |
74 }; | 73 }; |
75 | 74 |
76 inline void PacketDeleter::operator()(Packet* ptr) const { | 75 inline void PacketDeleter::operator()(Packet* ptr) const { |
77 DCHECK(ptr); | 76 DCHECK(ptr); |
78 ptr->Release(); | 77 ptr->Release(); |
79 } | 78 } |
80 | 79 |
81 } // namespace media | 80 } // namespace media |
82 } // namespace mojo | 81 } // namespace mojo |
83 | 82 |
84 #endif // SERVICES_MEDIA_FRAMEWORK_PACKET_H_ | 83 #endif // SERVICES_MEDIA_FRAMEWORK_PACKET_H_ |
OLD | NEW |