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 class Packet { |
| 31 public: |
| 32 // Creates a packet. If size is 0, payload must be nullptr and vice-versa. |
| 33 // If payload is not nullptr, an allocator must be provided. |
| 34 static PacketPtr Create( |
| 35 int64_t presentation_time, |
| 36 uint64_t duration, |
| 37 bool end_of_stream, |
| 38 uint64_t size, |
| 39 void* payload, |
| 40 Allocator* allocator); |
| 41 |
| 42 // Creates an end-of-stream packet with no payload. |
| 43 static PacketPtr CreateEndOfStream(int64_t presentation_time); |
| 44 |
| 45 virtual int64_t presentation_time() const = 0; |
| 46 |
| 47 virtual uint64_t duration() const = 0; |
| 48 |
| 49 virtual bool end_of_stream() const = 0; |
| 50 |
| 51 virtual uint64_t size() const = 0; |
| 52 |
| 53 virtual void* payload() const = 0; |
| 54 |
| 55 protected: |
| 56 virtual ~Packet() {} |
| 57 |
| 58 virtual void release() = 0; |
| 59 |
| 60 friend PacketDeleter; |
| 61 }; |
| 62 |
| 63 inline void PacketDeleter::operator()(Packet* ptr) const { |
| 64 DCHECK(ptr); |
| 65 ptr->release(); |
| 66 } |
| 67 |
| 68 } // namespace media |
| 69 } // namespace mojo |
| 70 |
| 71 #endif // SERVICES_MEDIA_FRAMEWORK_PACKET_H_ |
OLD | NEW |