Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef SERVICES_MEDIA_FRAMEWORK_PACKET_H_ | |
| 6 #define SERVICES_MEDIA_FRAMEWORK_PACKET_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "base/logging.h" | |
| 11 #include "services/media/framework/allocator.h" | |
| 12 #include "services/media/framework/ptr.h" | |
| 13 | |
| 14 namespace mojo { | |
| 15 namespace media { | |
| 16 | |
| 17 class Packet; | |
| 18 | |
| 19 // Used for PacketPtr. | |
| 20 struct PacketDeleter { | |
| 21 void operator()(Packet* ptr) const; | |
| 22 }; | |
| 23 | |
| 24 // Unique pointer for packets. | |
| 25 typedef UniquePtr<Packet, PacketDeleter> PacketPtr; | |
| 26 | |
| 27 // Media packet abstract base class. Subclasses may be defined as needed. | |
| 28 // Packet::Create and Packet::CreateEndOfStream use an implementation with | |
| 29 // no special behavior. | |
| 30 // TODO(dalesat): Revisit this definition: | |
| 31 // 1) We probably need an extensible way to add metadata to packets. | |
|
jeffbrown
2016/02/02 05:35:47
Worth asking whether the metadata is part of the p
dalesat
2016/02/02 21:46:39
Acknowledged.
| |
| 32 // 2) The relationship to the allocator could be clearer. | |
| 33 class Packet { | |
| 34 public: | |
| 35 // 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. | |
| 37 static PacketPtr Create( | |
| 38 int64_t presentation_time, | |
| 39 uint64_t duration, | |
| 40 bool end_of_stream, | |
| 41 uint64_t size, | |
| 42 void* payload, | |
| 43 Allocator* allocator); | |
| 44 | |
| 45 // 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 | |
| 47 // packet is released. | |
| 48 static PacketPtr CreateNoAllocator( | |
| 49 int64_t presentation_time, | |
| 50 uint64_t duration, | |
| 51 bool end_of_stream, | |
| 52 uint64_t size, | |
| 53 void* payload); | |
| 54 | |
| 55 // Creates an end-of-stream packet with no payload. | |
| 56 static PacketPtr CreateEndOfStream(int64_t presentation_time); | |
| 57 | |
| 58 virtual int64_t presentation_time() const = 0; | |
|
jeffbrown
2016/02/02 05:35:47
Virtual methods can't use accessor notation. So t
dalesat
2016/02/02 21:46:39
Acknowledged.
| |
| 59 | |
| 60 virtual uint64_t duration() const = 0; | |
| 61 | |
| 62 virtual bool end_of_stream() const = 0; | |
| 63 | |
| 64 virtual uint64_t size() const = 0; | |
| 65 | |
| 66 virtual void* payload() const = 0; | |
| 67 | |
| 68 protected: | |
| 69 virtual ~Packet() {} | |
| 70 | |
| 71 virtual void release() = 0; | |
|
jeffbrown
2016/02/02 05:35:47
Release()
dalesat
2016/02/02 21:46:39
Done.
| |
| 72 | |
| 73 friend PacketDeleter; | |
| 74 }; | |
| 75 | |
| 76 inline void PacketDeleter::operator()(Packet* ptr) const { | |
| 77 DCHECK(ptr); | |
| 78 ptr->release(); | |
| 79 } | |
| 80 | |
| 81 } // namespace media | |
| 82 } // namespace mojo | |
| 83 | |
| 84 #endif // SERVICES_MEDIA_FRAMEWORK_PACKET_H_ | |
| OLD | NEW |