2013-09-24 01:35:40 +00:00
|
|
|
// Copyright (c) 2012 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.
|
|
|
|
|
2017-12-20 00:56:36 +00:00
|
|
|
#ifndef PACKAGER_MEDIA_BASE_BYTE_QUEUE_H_
|
|
|
|
#define PACKAGER_MEDIA_BASE_BYTE_QUEUE_H_
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2014-09-30 23:52:58 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2022-11-04 22:46:41 +00:00
|
|
|
#include "packager/macros.h"
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2013-09-24 01:35:40 +00:00
|
|
|
namespace media {
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Represents a queue of bytes.
|
|
|
|
/// Data is added to the end of the queue via an Push() and removed via Pop().
|
|
|
|
/// The contents of the queue can be observed via the Peek() method. This class
|
|
|
|
/// manages the underlying storage of the queue and tries to minimize the
|
|
|
|
/// number of buffer copies when data is appended and removed.
|
2013-09-24 04:17:12 +00:00
|
|
|
class ByteQueue {
|
2013-09-24 01:35:40 +00:00
|
|
|
public:
|
|
|
|
ByteQueue();
|
|
|
|
~ByteQueue();
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Reset the queue to the empty state.
|
2013-09-24 01:35:40 +00:00
|
|
|
void Reset();
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Append new bytes to the end of the queue.
|
2014-09-30 21:52:21 +00:00
|
|
|
void Push(const uint8_t* data, int size);
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Get a pointer to the front of the queue and the queue size.
|
|
|
|
/// These values are only valid until the next Push() or Pop() call.
|
2014-09-30 21:52:21 +00:00
|
|
|
void Peek(const uint8_t** data, int* size) const;
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Remove a number of bytes from the front of the queue.
|
|
|
|
/// @param count specifies number of bytes to be popped.
|
2013-09-24 01:35:40 +00:00
|
|
|
void Pop(int count);
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Returns a pointer to the front of the queue.
|
2014-09-30 21:52:21 +00:00
|
|
|
uint8_t* front() const;
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<uint8_t[]> buffer_;
|
2013-09-24 01:35:40 +00:00
|
|
|
|
|
|
|
// Size of |buffer_|.
|
|
|
|
size_t size_;
|
|
|
|
|
|
|
|
// Offset from the start of |buffer_| that marks the front of the queue.
|
|
|
|
size_t offset_;
|
|
|
|
|
|
|
|
// Number of bytes stored in the queue.
|
|
|
|
int used_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ByteQueue);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2017-12-20 00:56:36 +00:00
|
|
|
#endif // PACKAGER_MEDIA_BASE_BYTE_QUEUE_H_
|