Chromium Code Reviews| Index: services/media/framework/packet.h |
| diff --git a/services/media/framework/packet.h b/services/media/framework/packet.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2337167e41ee5c17dfec22703fc36a20dd588a94 |
| --- /dev/null |
| +++ b/services/media/framework/packet.h |
| @@ -0,0 +1,84 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef SERVICES_MEDIA_FRAMEWORK_PACKET_H_ |
| +#define SERVICES_MEDIA_FRAMEWORK_PACKET_H_ |
| + |
| +#include <memory> |
| + |
| +#include "base/logging.h" |
| +#include "services/media/framework/allocator.h" |
| +#include "services/media/framework/ptr.h" |
| + |
| +namespace mojo { |
| +namespace media { |
| + |
| +class Packet; |
| + |
| +// Used for PacketPtr. |
| +struct PacketDeleter { |
| + void operator()(Packet* ptr) const; |
| +}; |
| + |
| +// Unique pointer for packets. |
| +typedef UniquePtr<Packet, PacketDeleter> PacketPtr; |
| + |
| +// Media packet abstract base class. Subclasses may be defined as needed. |
| +// Packet::Create and Packet::CreateEndOfStream use an implementation with |
| +// no special behavior. |
| +// TODO(dalesat): Revisit this definition: |
| +// 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.
|
| +// 2) The relationship to the allocator could be clearer. |
| +class Packet { |
| + public: |
| + // Creates a packet. If size is 0, payload must be nullptr and vice-versa. |
| + // If payload is not nullptr, an allocator must be provided. |
| + static PacketPtr Create( |
| + int64_t presentation_time, |
| + uint64_t duration, |
| + bool end_of_stream, |
| + uint64_t size, |
| + void* payload, |
| + Allocator* allocator); |
| + |
| + // Creates a packet. If size is 0, payload must be nullptr and vice-versa. |
| + // No allocator is provided, and the payload will not be released when the |
| + // packet is released. |
| + static PacketPtr CreateNoAllocator( |
| + int64_t presentation_time, |
| + uint64_t duration, |
| + bool end_of_stream, |
| + uint64_t size, |
| + void* payload); |
| + |
| + // Creates an end-of-stream packet with no payload. |
| + static PacketPtr CreateEndOfStream(int64_t presentation_time); |
| + |
| + 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.
|
| + |
| + virtual uint64_t duration() const = 0; |
| + |
| + virtual bool end_of_stream() const = 0; |
| + |
| + virtual uint64_t size() const = 0; |
| + |
| + virtual void* payload() const = 0; |
| + |
| + protected: |
| + virtual ~Packet() {} |
| + |
| + virtual void release() = 0; |
|
jeffbrown
2016/02/02 05:35:47
Release()
dalesat
2016/02/02 21:46:39
Done.
|
| + |
| + friend PacketDeleter; |
| +}; |
| + |
| +inline void PacketDeleter::operator()(Packet* ptr) const { |
| + DCHECK(ptr); |
| + ptr->release(); |
| +} |
| + |
| +} // namespace media |
| +} // namespace mojo |
| + |
| +#endif // SERVICES_MEDIA_FRAMEWORK_PACKET_H_ |