2014-04-30 23:22:15 +00:00
|
|
|
// Copyright 2014 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
|
|
|
|
|
2017-07-10 18:26:22 +00:00
|
|
|
#include "packager/file/udp_file.h"
|
2014-04-30 23:22:15 +00:00
|
|
|
|
2017-01-10 18:05:28 +00:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include <ws2tcpip.h>
|
|
|
|
#define close closesocket
|
2019-09-05 21:30:36 +00:00
|
|
|
#define EINTR_CODE WSAEINTR
|
2017-01-10 18:05:28 +00:00
|
|
|
#else
|
2014-04-30 23:22:15 +00:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <errno.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
|
|
|
#include <string.h>
|
2014-04-30 23:22:15 +00:00
|
|
|
#include <sys/socket.h>
|
2018-08-15 00:21:29 +00:00
|
|
|
#include <sys/time.h>
|
2014-07-01 17:26:43 +00:00
|
|
|
#include <unistd.h>
|
2017-01-10 18:05:28 +00:00
|
|
|
#define INVALID_SOCKET -1
|
2019-09-05 21:30:36 +00:00
|
|
|
#define EINTR_CODE EINTR
|
2017-07-26 20:09:21 +00:00
|
|
|
// IP_MULTICAST_ALL has been supported since kernel version 2.6.31 but we may be
|
|
|
|
// building on a machine that is older than that.
|
|
|
|
#ifndef IP_MULTICAST_ALL
|
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
|
|
|
#define IP_MULTICAST_ALL 49
|
2017-07-26 20:09:21 +00:00
|
|
|
#endif
|
2017-01-10 18:05:28 +00:00
|
|
|
#endif // defined(OS_WIN)
|
2014-07-01 17:26:43 +00:00
|
|
|
|
2014-09-30 23:52:58 +00:00
|
|
|
#include <limits>
|
|
|
|
|
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 "glog/logging.h"
|
2017-07-10 18:26:22 +00:00
|
|
|
#include "packager/file/udp_options.h"
|
2014-04-30 23:22:15 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2014-04-30 23:22:15 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2016-10-05 01:17:07 +00:00
|
|
|
bool IsIpv4MulticastAddress(const struct in_addr& addr) {
|
|
|
|
return (ntohl(addr.s_addr) & 0xf0000000) == 0xe0000000;
|
2014-04-30 23:22:15 +00:00
|
|
|
}
|
|
|
|
|
2019-09-05 21:30:36 +00:00
|
|
|
int GetSocketErrorCode() {
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
return WSAGetLastError();
|
|
|
|
#else
|
|
|
|
return errno;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-04-30 23:22:15 +00:00
|
|
|
} // anonymous namespace
|
|
|
|
|
2017-07-10 18:26:22 +00:00
|
|
|
UdpFile::UdpFile(const char* file_name)
|
|
|
|
: File(file_name), socket_(INVALID_SOCKET) {}
|
2014-04-30 23:22:15 +00:00
|
|
|
|
|
|
|
UdpFile::~UdpFile() {}
|
|
|
|
|
|
|
|
bool UdpFile::Close() {
|
2017-01-10 18:05:28 +00:00
|
|
|
if (socket_ != INVALID_SOCKET) {
|
2014-04-30 23:22:15 +00:00
|
|
|
close(socket_);
|
2017-01-10 18:05:28 +00:00
|
|
|
socket_ = INVALID_SOCKET;
|
2014-04-30 23:22:15 +00:00
|
|
|
}
|
|
|
|
delete this;
|
2019-11-17 06:17:17 +00:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
if (wsa_started_)
|
|
|
|
WSACleanup();
|
|
|
|
#endif
|
2014-04-30 23:22:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
int64_t UdpFile::Read(void* buffer, uint64_t length) {
|
2014-04-30 23:22:15 +00:00
|
|
|
DCHECK(buffer);
|
|
|
|
DCHECK_GE(length, 65535u)
|
|
|
|
<< "Buffer may be too small to read entire datagram.";
|
|
|
|
|
2017-01-10 18:05:28 +00:00
|
|
|
if (socket_ == INVALID_SOCKET)
|
2014-04-30 23:22:15 +00:00
|
|
|
return -1;
|
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
int64_t result;
|
2014-04-30 23:22:15 +00:00
|
|
|
do {
|
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
|
|
|
result = recvfrom(socket_, reinterpret_cast<char*>(buffer),
|
|
|
|
static_cast<int>(length), 0, NULL, 0);
|
2019-09-05 21:30:36 +00:00
|
|
|
} while (result == -1 && GetSocketErrorCode() == EINTR_CODE);
|
2014-04-30 23:22:15 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
int64_t UdpFile::Write(const void* buffer, uint64_t length) {
|
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
|
|
|
UNUSED(buffer);
|
|
|
|
UNUSED(length);
|
|
|
|
NOTIMPLEMENTED() << "UdpFile is unwritable!";
|
2014-04-30 23:22:15 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
int64_t UdpFile::Size() {
|
2017-01-10 18:05:28 +00:00
|
|
|
if (socket_ == INVALID_SOCKET)
|
2014-04-30 23:22:15 +00:00
|
|
|
return -1;
|
|
|
|
|
2014-09-30 23:52:58 +00:00
|
|
|
return std::numeric_limits<int64_t>::max();
|
2014-04-30 23:22:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool UdpFile::Flush() {
|
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
|
|
|
NOTIMPLEMENTED() << "UdpFile is unflushable!";
|
2014-04-30 23:22:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-05-20 17:14:36 +00:00
|
|
|
bool UdpFile::Seek(uint64_t position) {
|
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
|
|
|
UNUSED(position);
|
|
|
|
NOTIMPLEMENTED() << "UdpFile is unseekable!";
|
2015-05-20 17:14:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UdpFile::Tell(uint64_t* position) {
|
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
|
|
|
UNUSED(position);
|
|
|
|
NOTIMPLEMENTED() << "UdpFile is unseekable!";
|
2015-05-20 17:14:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-04-30 23:22:15 +00:00
|
|
|
class ScopedSocket {
|
|
|
|
public:
|
2017-07-10 18:26:22 +00:00
|
|
|
explicit ScopedSocket(SOCKET sock_fd) : sock_fd_(sock_fd) {}
|
2014-04-30 23:22:15 +00:00
|
|
|
|
|
|
|
~ScopedSocket() {
|
2017-01-10 18:05:28 +00:00
|
|
|
if (sock_fd_ != INVALID_SOCKET)
|
2014-04-30 23:22:15 +00:00
|
|
|
close(sock_fd_);
|
|
|
|
}
|
|
|
|
|
2017-01-10 18:05:28 +00:00
|
|
|
SOCKET get() { return sock_fd_; }
|
2014-04-30 23:22:15 +00:00
|
|
|
|
2017-01-10 18:05:28 +00:00
|
|
|
SOCKET release() {
|
|
|
|
SOCKET socket = sock_fd_;
|
|
|
|
sock_fd_ = INVALID_SOCKET;
|
2014-04-30 23:22:15 +00:00
|
|
|
return socket;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-01-10 18:05:28 +00:00
|
|
|
SOCKET sock_fd_;
|
2014-04-30 23:22:15 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ScopedSocket);
|
|
|
|
};
|
|
|
|
|
|
|
|
bool UdpFile::Open() {
|
2017-01-10 18:05:28 +00:00
|
|
|
#if defined(OS_WIN)
|
2019-11-17 06:17:17 +00:00
|
|
|
WSADATA wsa_data;
|
|
|
|
int wsa_error = WSAStartup(MAKEWORD(2, 2), &wsa_data);
|
|
|
|
if (wsa_error != 0) {
|
|
|
|
LOG(ERROR) << "Winsock start up failed with error " << wsa_error;
|
2017-01-10 18:05:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-11-17 06:17:17 +00:00
|
|
|
wsa_started_ = true;
|
2017-01-10 18:05:28 +00:00
|
|
|
#endif // defined(OS_WIN)
|
|
|
|
|
|
|
|
DCHECK_EQ(INVALID_SOCKET, socket_);
|
2014-04-30 23:22:15 +00:00
|
|
|
|
2016-10-05 01:17:07 +00:00
|
|
|
std::unique_ptr<UdpOptions> options =
|
|
|
|
UdpOptions::ParseFromString(file_name());
|
|
|
|
if (!options)
|
2014-04-30 23:22:15 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
ScopedSocket new_socket(socket(AF_INET, SOCK_DGRAM, 0));
|
2017-01-10 18:05:28 +00:00
|
|
|
if (new_socket.get() == INVALID_SOCKET) {
|
2019-09-05 21:30:36 +00:00
|
|
|
LOG(ERROR) << "Could not allocate socket, error = " << GetSocketErrorCode();
|
2014-04-30 23:22:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-10 18:05:28 +00:00
|
|
|
struct in_addr local_in_addr = {0};
|
2017-07-10 18:26:22 +00:00
|
|
|
if (inet_pton(AF_INET, options->address().c_str(), &local_in_addr) != 1) {
|
2016-10-05 01:17:07 +00:00
|
|
|
LOG(ERROR) << "Malformed IPv4 address " << options->address();
|
2016-10-04 22:51:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-10-05 01:17:07 +00:00
|
|
|
|
2017-01-10 18:05:28 +00:00
|
|
|
// TODO(kqyang): Support IPv6.
|
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
|
|
|
struct sockaddr_in local_sock_addr;
|
|
|
|
memset(&local_sock_addr, 0, sizeof(local_sock_addr));
|
2017-01-10 18:05:28 +00:00
|
|
|
local_sock_addr.sin_family = AF_INET;
|
|
|
|
local_sock_addr.sin_port = htons(options->port());
|
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
|
|
|
|
2017-01-10 18:05:28 +00:00
|
|
|
const bool is_multicast = IsIpv4MulticastAddress(local_in_addr);
|
|
|
|
if (is_multicast) {
|
|
|
|
local_sock_addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
|
|
|
} else {
|
|
|
|
local_sock_addr.sin_addr = local_in_addr;
|
|
|
|
}
|
|
|
|
|
2016-10-05 01:17:07 +00:00
|
|
|
if (options->reuse()) {
|
|
|
|
const int optval = 1;
|
2017-01-10 18:05:28 +00:00
|
|
|
if (setsockopt(new_socket.get(), SOL_SOCKET, SO_REUSEADDR,
|
2017-07-10 18:26:22 +00:00
|
|
|
reinterpret_cast<const char*>(&optval),
|
2016-10-05 01:17:07 +00:00
|
|
|
sizeof(optval)) < 0) {
|
2019-09-05 21:30:36 +00:00
|
|
|
LOG(ERROR) << "Could not apply the SO_REUSEADDR property to the UDP "
|
|
|
|
"socket, error = "
|
|
|
|
<< GetSocketErrorCode();
|
2016-10-05 01:17:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-30 23:22:15 +00:00
|
|
|
if (bind(new_socket.get(),
|
|
|
|
reinterpret_cast<struct sockaddr*>(&local_sock_addr),
|
2019-08-02 00:32:28 +00:00
|
|
|
sizeof(local_sock_addr)) < 0) {
|
2019-09-05 21:30:36 +00:00
|
|
|
LOG(ERROR) << "Could not bind UDP socket, error = " << GetSocketErrorCode();
|
2014-04-30 23:22:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-10 18:05:28 +00:00
|
|
|
if (is_multicast) {
|
2018-03-06 18:09:28 +00:00
|
|
|
if (options->is_source_specific_multicast()) {
|
|
|
|
struct ip_mreq_source source_multicast_group;
|
|
|
|
|
|
|
|
source_multicast_group.imr_multiaddr = local_in_addr;
|
|
|
|
if (inet_pton(AF_INET,
|
|
|
|
options->interface_address().c_str(),
|
|
|
|
&source_multicast_group.imr_interface) != 1) {
|
|
|
|
LOG(ERROR) << "Malformed IPv4 interface address "
|
|
|
|
<< options->interface_address();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (inet_pton(AF_INET,
|
|
|
|
options->source_address().c_str(),
|
|
|
|
&source_multicast_group.imr_sourceaddr) != 1) {
|
|
|
|
LOG(ERROR) << "Malformed IPv4 source specific multicast address "
|
|
|
|
<< options->source_address();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setsockopt(new_socket.get(),
|
|
|
|
IPPROTO_IP,
|
|
|
|
IP_ADD_SOURCE_MEMBERSHIP,
|
|
|
|
reinterpret_cast<const char*>(&source_multicast_group),
|
|
|
|
sizeof(source_multicast_group)) < 0) {
|
2019-09-05 21:30:36 +00:00
|
|
|
LOG(ERROR) << "Failed to join multicast group, error = "
|
|
|
|
<< GetSocketErrorCode();
|
|
|
|
return false;
|
2018-03-06 18:09:28 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// this is a v2 join without a specific source.
|
|
|
|
struct ip_mreq multicast_group;
|
|
|
|
|
|
|
|
multicast_group.imr_multiaddr = local_in_addr;
|
|
|
|
|
|
|
|
if (inet_pton(AF_INET, options->interface_address().c_str(),
|
|
|
|
&multicast_group.imr_interface) != 1) {
|
|
|
|
LOG(ERROR) << "Malformed IPv4 interface address "
|
|
|
|
<< options->interface_address();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setsockopt(new_socket.get(), IPPROTO_IP, IP_ADD_MEMBERSHIP,
|
2019-09-05 21:30:36 +00:00
|
|
|
reinterpret_cast<const char*>(&multicast_group),
|
|
|
|
sizeof(multicast_group)) < 0) {
|
|
|
|
LOG(ERROR) << "Failed to join multicast group, error = "
|
|
|
|
<< GetSocketErrorCode();
|
2018-03-06 18:09:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2017-07-26 20:09:21 +00:00
|
|
|
|
|
|
|
#if defined(__linux__)
|
|
|
|
// Disable IP_MULTICAST_ALL to avoid interference caused when two sockets
|
|
|
|
// are bound to the same port but joined to different multicast groups.
|
|
|
|
const int optval_zero = 0;
|
|
|
|
if (setsockopt(new_socket.get(), IPPROTO_IP, IP_MULTICAST_ALL,
|
|
|
|
reinterpret_cast<const char*>(&optval_zero),
|
|
|
|
sizeof(optval_zero)) < 0 &&
|
2019-09-05 21:30:36 +00:00
|
|
|
GetSocketErrorCode() != ENOPROTOOPT) {
|
|
|
|
LOG(ERROR) << "Failed to disable IP_MULTICAST_ALL option, error = "
|
|
|
|
<< GetSocketErrorCode();
|
2017-07-26 20:09:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif // #if defined(__linux__)
|
2014-04-30 23:22:15 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 01:17:07 +00:00
|
|
|
// Set timeout if needed.
|
|
|
|
if (options->timeout_us() != 0) {
|
|
|
|
struct timeval tv;
|
|
|
|
tv.tv_sec = options->timeout_us() / 1000000;
|
|
|
|
tv.tv_usec = options->timeout_us() % 1000000;
|
|
|
|
if (setsockopt(new_socket.get(), SOL_SOCKET, SO_RCVTIMEO,
|
2018-06-07 18:20:12 +00:00
|
|
|
reinterpret_cast<const char*>(&tv), sizeof(tv)) < 0) {
|
2019-09-05 21:30:36 +00:00
|
|
|
LOG(ERROR) << "Failed to set socket timeout, error = "
|
|
|
|
<< GetSocketErrorCode();
|
2016-10-05 01:17:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-07 18:20:12 +00:00
|
|
|
if (options->buffer_size() > 0) {
|
|
|
|
const int receive_buffer_size = options->buffer_size();
|
|
|
|
if (setsockopt(new_socket.get(), SOL_SOCKET, SO_RCVBUF,
|
|
|
|
reinterpret_cast<const char*>(&receive_buffer_size),
|
|
|
|
sizeof(receive_buffer_size)) < 0) {
|
2019-09-05 21:30:36 +00:00
|
|
|
LOG(ERROR) << "Failed to set the maximum receive buffer size, error = "
|
|
|
|
<< GetSocketErrorCode();
|
2018-06-07 18:20:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-30 23:22:15 +00:00
|
|
|
socket_ = new_socket.release();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|