2015-03-13 00:54:12 +00:00
|
|
|
// Copyright 2015 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
|
|
|
|
#ifndef PACKAGER_FILE_IO_CACHE_H_
|
|
|
|
#define PACKAGER_FILE_IO_CACHE_H_
|
|
|
|
|
|
|
|
#include <stdint.h>
|
feat: First phase of CMake build system implementation (#1072)
There are a lot of changes in this first phase, because there was a
lot of infrastructure required to get some meaningful amount of
porting done. Future PRs should be simpler.
<b>Summary of changes:</b><details>
- Remove old deps:
- boringssl (replaced with mbedtls, lighter, easier to build)
- gflags (replaced with absl::flags)
- Chromium build tools
- New deps to replace parts of Chromium base:
- abseil-cpp
- glog
- nlohmann::json (for tests only)
- Submodules, updates, and CMake build rules for third-party
libraries:
- curl
- gmock/gtest
- Ported internal libraries and their tests by removing Chromium deps
and adding CMake build rules:
- file (now using C++17 filesystem APIs)
- license_notice
- status
- version
- Test improvements
- Removed file tests that can never be re-enabled
- Re-enabled all other disabled file tests
- Debug JSON values when HTTP tests fail
- Fixed chunked-encoding issues in HTTP tests
- Updated and refactored Dockerfiles testing
- All docker files working, with OS versions updated to meet the
new tool requirements
- Local docker builds no longer write files to your working
directory as root
- Local docker builds can now be run in parallel without clobbering
each others' build outputs
- DEBUG=1 can drop you into an interactive shell when a docker
build fails
- Updated and heavily refactored workflows and Dockerfiles
- All docker files now tested in parallel on GitHub, speeding up CI
- All common workflow components broken out and using workflow_call
instead of custom actions
- Self-hosted runners now optional, to make testing easier on forks
- CMake porting works-in-process can now be fully tested on GitHub
- Building ported libraries and passing ported tests on all three
platforms!
- CI hacks for macOS removed, now testing on macos-latest!
- Python2 no longer required! (Only Python3)
- Using strict build flags, treating all warnings as errors.
</details>
<b>Required to build:</b>
- CMake >= 3.16
- Python 3
- A compiler supporting C++ >= 17
- g++ >= 9 if using GCC (Clang also fine)
- MSVC for Windows
<b>Still needs work:</b><details>
- Moving other dependencies into submodules (if we keep them):
- apple_apsl
- icu
- libevent
- libpng
- libwebm
- libxml
- modp_b64
- protobuf
- zlib
- Port remaining internal libraries:
- app
- hls
- media/base
- media/chunking
- media/codecs
- media/crypto
- media/demuxer
- media/event
- media/formats/dvb
- media/formats/mp2t
- media/formats/mp4
- media/formats/packed_audio
- media/formats/ttml
- media/formats/webm
- media/formats/webvtt
- media/formats/wvm
- media/origin
- media/public
- media/replicator
- media/trick_play
- mpd
- Port main application
- Add logging flags in absl and connect them to glog (which expects
gflags)
- Port pssh-box.py
- Port main test targets (packager_test.py and packager_app.py)
- Updating all requirement and build documentation
- Remove any remaining refs to gclient, depot_tools, ninja
- Update and complete release workflows using release-please
</details>
Issue #346 (Switch to abseil)
Issue #1047 (New build system)
2022-08-16 18:34:51 +00:00
|
|
|
|
2015-03-13 00:54:12 +00:00
|
|
|
#include <vector>
|
feat: First phase of CMake build system implementation (#1072)
There are a lot of changes in this first phase, because there was a
lot of infrastructure required to get some meaningful amount of
porting done. Future PRs should be simpler.
<b>Summary of changes:</b><details>
- Remove old deps:
- boringssl (replaced with mbedtls, lighter, easier to build)
- gflags (replaced with absl::flags)
- Chromium build tools
- New deps to replace parts of Chromium base:
- abseil-cpp
- glog
- nlohmann::json (for tests only)
- Submodules, updates, and CMake build rules for third-party
libraries:
- curl
- gmock/gtest
- Ported internal libraries and their tests by removing Chromium deps
and adding CMake build rules:
- file (now using C++17 filesystem APIs)
- license_notice
- status
- version
- Test improvements
- Removed file tests that can never be re-enabled
- Re-enabled all other disabled file tests
- Debug JSON values when HTTP tests fail
- Fixed chunked-encoding issues in HTTP tests
- Updated and refactored Dockerfiles testing
- All docker files working, with OS versions updated to meet the
new tool requirements
- Local docker builds no longer write files to your working
directory as root
- Local docker builds can now be run in parallel without clobbering
each others' build outputs
- DEBUG=1 can drop you into an interactive shell when a docker
build fails
- Updated and heavily refactored workflows and Dockerfiles
- All docker files now tested in parallel on GitHub, speeding up CI
- All common workflow components broken out and using workflow_call
instead of custom actions
- Self-hosted runners now optional, to make testing easier on forks
- CMake porting works-in-process can now be fully tested on GitHub
- Building ported libraries and passing ported tests on all three
platforms!
- CI hacks for macOS removed, now testing on macos-latest!
- Python2 no longer required! (Only Python3)
- Using strict build flags, treating all warnings as errors.
</details>
<b>Required to build:</b>
- CMake >= 3.16
- Python 3
- A compiler supporting C++ >= 17
- g++ >= 9 if using GCC (Clang also fine)
- MSVC for Windows
<b>Still needs work:</b><details>
- Moving other dependencies into submodules (if we keep them):
- apple_apsl
- icu
- libevent
- libpng
- libwebm
- libxml
- modp_b64
- protobuf
- zlib
- Port remaining internal libraries:
- app
- hls
- media/base
- media/chunking
- media/codecs
- media/crypto
- media/demuxer
- media/event
- media/formats/dvb
- media/formats/mp2t
- media/formats/mp4
- media/formats/packed_audio
- media/formats/ttml
- media/formats/webm
- media/formats/webvtt
- media/formats/wvm
- media/origin
- media/public
- media/replicator
- media/trick_play
- mpd
- Port main application
- Add logging flags in absl and connect them to glog (which expects
gflags)
- Port pssh-box.py
- Port main test targets (packager_test.py and packager_app.py)
- Updating all requirement and build documentation
- Remove any remaining refs to gclient, depot_tools, ninja
- Update and complete release workflows using release-please
</details>
Issue #346 (Switch to abseil)
Issue #1047 (New build system)
2022-08-16 18:34:51 +00:00
|
|
|
|
|
|
|
#include "absl/synchronization/mutex.h"
|
|
|
|
#include "packager/common.h"
|
2015-03-13 00:54:12 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2015-03-13 00:54:12 +00:00
|
|
|
|
|
|
|
/// Declaration of class which implements a thread-safe circular buffer.
|
|
|
|
class IoCache {
|
|
|
|
public:
|
|
|
|
explicit IoCache(uint64_t cache_size);
|
2015-07-22 23:40:45 +00:00
|
|
|
~IoCache();
|
2015-03-13 00:54:12 +00:00
|
|
|
|
|
|
|
/// Read data from the cache. This function may block until there is data in
|
|
|
|
/// the cache.
|
|
|
|
/// @param buffer is a buffer into which to read the data from the cache.
|
|
|
|
/// @param size is the size of @a buffer.
|
|
|
|
/// @return the number of bytes read into @a buffer, or 0 if the call
|
2015-03-19 18:28:04 +00:00
|
|
|
/// unblocked because the cache has been closed and is empty.
|
2015-03-18 21:35:25 +00:00
|
|
|
uint64_t Read(void* buffer, uint64_t size);
|
2015-03-13 00:54:12 +00:00
|
|
|
|
|
|
|
/// Write data to the cache. This function may block until there is enough
|
|
|
|
/// room in the cache.
|
|
|
|
/// @param buffer is a buffer containing the data to be written to the cache.
|
|
|
|
/// @param size is the size of the data to be written to the cache.
|
|
|
|
/// @return the amount of data written to the buffer (which will equal
|
|
|
|
/// @a data), or 0 if the call unblocked because the cache has been
|
|
|
|
/// closed.
|
2015-03-18 21:35:25 +00:00
|
|
|
uint64_t Write(const void* buffer, uint64_t size);
|
2015-03-13 00:54:12 +00:00
|
|
|
|
|
|
|
/// Empties the cache.
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
/// Close the cache. This will call any blocking calls to unblock, and the
|
2015-10-16 20:10:42 +00:00
|
|
|
/// cache won't be usable until Reopened.
|
2015-03-13 00:54:12 +00:00
|
|
|
void Close();
|
|
|
|
|
2015-10-16 20:10:42 +00:00
|
|
|
/// @return true if the cache is closed, false otherwise.
|
|
|
|
bool closed() { return closed_; }
|
|
|
|
|
|
|
|
/// Reopens the cache. Any data still in the cache will be lost.
|
|
|
|
void Reopen();
|
|
|
|
|
2015-03-13 00:54:12 +00:00
|
|
|
/// Returns the number of bytes in the cache.
|
|
|
|
/// @return the number of bytes in the cache.
|
|
|
|
uint64_t BytesCached();
|
|
|
|
|
|
|
|
/// Returns the number of free bytes in the cache.
|
|
|
|
/// @return the number of free bytes in the cache.
|
|
|
|
uint64_t BytesFree();
|
|
|
|
|
2015-03-19 18:28:04 +00:00
|
|
|
/// Waits until the cache is empty or has been closed.
|
|
|
|
void WaitUntilEmptyOrClosed();
|
|
|
|
|
2015-03-13 00:54:12 +00:00
|
|
|
private:
|
|
|
|
uint64_t BytesCachedInternal();
|
|
|
|
uint64_t BytesFreeInternal();
|
|
|
|
|
|
|
|
const uint64_t cache_size_;
|
feat: First phase of CMake build system implementation (#1072)
There are a lot of changes in this first phase, because there was a
lot of infrastructure required to get some meaningful amount of
porting done. Future PRs should be simpler.
<b>Summary of changes:</b><details>
- Remove old deps:
- boringssl (replaced with mbedtls, lighter, easier to build)
- gflags (replaced with absl::flags)
- Chromium build tools
- New deps to replace parts of Chromium base:
- abseil-cpp
- glog
- nlohmann::json (for tests only)
- Submodules, updates, and CMake build rules for third-party
libraries:
- curl
- gmock/gtest
- Ported internal libraries and their tests by removing Chromium deps
and adding CMake build rules:
- file (now using C++17 filesystem APIs)
- license_notice
- status
- version
- Test improvements
- Removed file tests that can never be re-enabled
- Re-enabled all other disabled file tests
- Debug JSON values when HTTP tests fail
- Fixed chunked-encoding issues in HTTP tests
- Updated and refactored Dockerfiles testing
- All docker files working, with OS versions updated to meet the
new tool requirements
- Local docker builds no longer write files to your working
directory as root
- Local docker builds can now be run in parallel without clobbering
each others' build outputs
- DEBUG=1 can drop you into an interactive shell when a docker
build fails
- Updated and heavily refactored workflows and Dockerfiles
- All docker files now tested in parallel on GitHub, speeding up CI
- All common workflow components broken out and using workflow_call
instead of custom actions
- Self-hosted runners now optional, to make testing easier on forks
- CMake porting works-in-process can now be fully tested on GitHub
- Building ported libraries and passing ported tests on all three
platforms!
- CI hacks for macOS removed, now testing on macos-latest!
- Python2 no longer required! (Only Python3)
- Using strict build flags, treating all warnings as errors.
</details>
<b>Required to build:</b>
- CMake >= 3.16
- Python 3
- A compiler supporting C++ >= 17
- g++ >= 9 if using GCC (Clang also fine)
- MSVC for Windows
<b>Still needs work:</b><details>
- Moving other dependencies into submodules (if we keep them):
- apple_apsl
- icu
- libevent
- libpng
- libwebm
- libxml
- modp_b64
- protobuf
- zlib
- Port remaining internal libraries:
- app
- hls
- media/base
- media/chunking
- media/codecs
- media/crypto
- media/demuxer
- media/event
- media/formats/dvb
- media/formats/mp2t
- media/formats/mp4
- media/formats/packed_audio
- media/formats/ttml
- media/formats/webm
- media/formats/webvtt
- media/formats/wvm
- media/origin
- media/public
- media/replicator
- media/trick_play
- mpd
- Port main application
- Add logging flags in absl and connect them to glog (which expects
gflags)
- Port pssh-box.py
- Port main test targets (packager_test.py and packager_app.py)
- Updating all requirement and build documentation
- Remove any remaining refs to gclient, depot_tools, ninja
- Update and complete release workflows using release-please
</details>
Issue #346 (Switch to abseil)
Issue #1047 (New build system)
2022-08-16 18:34:51 +00:00
|
|
|
absl::Mutex mutex_;
|
|
|
|
absl::CondVar read_event_ GUARDED_BY(mutex_);
|
|
|
|
absl::CondVar write_event_ GUARDED_BY(mutex_);
|
|
|
|
std::vector<uint8_t> circular_buffer_ GUARDED_BY(mutex_);
|
|
|
|
const uint8_t* end_ptr_ GUARDED_BY(mutex_);
|
|
|
|
uint8_t* r_ptr_ GUARDED_BY(mutex_);
|
|
|
|
uint8_t* w_ptr_ GUARDED_BY(mutex_);
|
|
|
|
bool closed_ GUARDED_BY(mutex_);
|
2015-03-13 00:54:12 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(IoCache);
|
|
|
|
};
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2015-03-13 00:54:12 +00:00
|
|
|
|
|
|
|
#endif // PACKAGER_FILE_IO_CACHE_H
|