Delete dead code in webrtc
Bug: 141887532
Test: locally
Change-Id: I746401883a4fdf49e705bb66143f8d1238b53aa5
diff --git a/host/frontend/gcastv2/https/Android.bp b/host/frontend/gcastv2/https/Android.bp
index a41fbe0..47b3783 100644
--- a/host/frontend/gcastv2/https/Android.bp
+++ b/host/frontend/gcastv2/https/Android.bp
@@ -15,18 +15,7 @@
"RunLoop.cpp",
"Support.cpp",
],
- target: {
- host: {
- cflags: [
- "-DTARGET_ANDROID",
- ],
- },
- android: {
- cflags: [
- "-DTARGET_ANDROID_DEVICE",
- ],
- },
- },
+ defaults: ["cuttlefish_host_only"],
static_libs: [
"libandroidglue",
],
@@ -39,20 +28,3 @@
export_include_dirs: ["include"],
}
-cc_library_static {
- name: "librunloop_device_nojava",
- vendor_available: true,
- srcs: [
- "RunLoop.cpp",
- "Support.cpp",
- ],
- cflags: [
- "-DTARGET_ANDROID_DEVICE_NO_JAVA",
- ],
- shared_libs: [
- "libbase",
- ],
- local_include_dirs: ["include"],
- export_include_dirs: ["include"],
-}
-
diff --git a/host/frontend/gcastv2/https/ClientSocket.cpp b/host/frontend/gcastv2/https/ClientSocket.cpp
index c4788ac..9e095a5 100644
--- a/host/frontend/gcastv2/https/ClientSocket.cpp
+++ b/host/frontend/gcastv2/https/ClientSocket.cpp
@@ -9,19 +9,6 @@
#include <cstdlib>
-#if defined(TARGET_IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED < 110000
-void *operator new(size_t size, std::align_val_t align) {
- void *data;
- posix_memalign(&data, static_cast<size_t>(align), size);
-
- return data;
-}
-
-void operator delete(void *data, std::align_val_t align) {
- free(data);
-}
-#endif
-
ClientSocket::ClientSocket(
std::shared_ptr<RunLoop> rl,
HTTPServer *server,
diff --git a/host/frontend/gcastv2/https/HTTPServer.cpp b/host/frontend/gcastv2/https/HTTPServer.cpp
index bff693d..4dd2e98 100644
--- a/host/frontend/gcastv2/https/HTTPServer.cpp
+++ b/host/frontend/gcastv2/https/HTTPServer.cpp
@@ -10,11 +10,6 @@
#include <map>
#include <string>
-#if defined(TARGET_MAC) || defined(TARGET_IOS)
-#include <CommonCrypto/CommonDigest.h>
-#endif
-
-#if defined(TARGET_ANDROID) || defined(TARGET_ANDROID_DEVICE)
#include <openssl/sha.h>
#define CC_SHA1_CTX SHA_CTX
@@ -22,7 +17,6 @@
#define CC_SHA1_Update SHA1_Update
#define CC_SHA1_Final SHA1_Final
#define CC_LONG size_t
-#endif
HTTPServer::HTTPServer(
std::shared_ptr<RunLoop> runLoop,
@@ -69,13 +63,6 @@
{ 505, "HTTP Version Not Supported" },
};
-#if 0
- LOG(INFO)
- << "handleSingleRequest on socket " << clientSocket->fd() << std::endl;
-
- hexdump(data, size);
-#endif
-
HTTPRequest request;
request.setTo(data, size);
diff --git a/host/frontend/gcastv2/https/RunLoop.cpp b/host/frontend/gcastv2/https/RunLoop.cpp
index e49d598..4b4cbe6 100644
--- a/host/frontend/gcastv2/https/RunLoop.cpp
+++ b/host/frontend/gcastv2/https/RunLoop.cpp
@@ -2,15 +2,7 @@
#include <https/Support.h>
-#ifdef TARGET_ANDROID_DEVICE
-#include <helpers/JavaThread.h>
-#endif
-
-#ifdef TARGET_ANDROID_DEVICE_NO_JAVA
-#include <android-base/logging.h>
-#else
#include <media/stagefright/foundation/ADebug.h>
-#endif
#include <cstring>
#include <fcntl.h>
@@ -49,11 +41,7 @@
: RunLoop() {
mName = name;
-#ifdef TARGET_ANDROID_DEVICE
- mThread = android::createJavaThread([this]{ run(); });
-#else
mThread = std::thread([this]{ run(); });
-#endif
}
RunLoop::~RunLoop() {
diff --git a/host/frontend/gcastv2/https/SSLSocket.cpp b/host/frontend/gcastv2/https/SSLSocket.cpp
index bcf2053..49e4193 100644
--- a/host/frontend/gcastv2/https/SSLSocket.cpp
+++ b/host/frontend/gcastv2/https/SSLSocket.cpp
@@ -47,117 +47,18 @@
SSL_set_bio(mSSL.get(), mBioR, mBioW);
}
-#ifdef TARGET_ANDROID_DEVICE
-
-static bool isResourcePath(const std::string &path, std::string *name) {
- static const char *const kPrefix = "keystore:";
- static const size_t kPrefixLen = strlen(kPrefix);
-
- if (path.substr(0, kPrefixLen) != kPrefix) {
- return false;
- }
-
- *name = path.substr(kPrefixLen);
-
- return true;
-}
-
-#endif
-
bool SSLSocket::useCertificate(const std::string &path) {
-#ifdef TARGET_ANDROID_DEVICE
- std::string name;
- if (isResourcePath(path, &name)) {
- std::vector<uint8_t> data;
- if (!getCertificateOrKey(name, &data)) {
- return false;
- }
-
- std::unique_ptr<BIO, std::function<void(BIO *)>> cbio(
- BIO_new_mem_buf(data.data(), data.size()), BIO_free);
-
- X509 *cert = PEM_read_bio_X509(cbio.get(), nullptr, 0, nullptr);
-
- return cert != nullptr && 1 == SSL_use_certificate(mSSL.get(), cert);
- }
-#endif
-
return 1 == SSL_use_certificate_file(
mSSL.get(), path.c_str(), SSL_FILETYPE_PEM);
}
bool SSLSocket::usePrivateKey(const std::string &path) {
-#ifdef TARGET_ANDROID_DEVICE
- std::string name;
- if (isResourcePath(path, &name)) {
- std::vector<uint8_t> data;
- if (!getCertificateOrKey(name, &data)) {
- return false;
- }
-
- std::unique_ptr<BIO, std::function<void(BIO *)>> cbio(
- BIO_new_mem_buf(data.data(), data.size()), BIO_free);
-
- RSA *key = PEM_read_bio_RSAPrivateKey(cbio.get(), nullptr, 0, nullptr);
-
- return key != nullptr
- && 1 == SSL_use_RSAPrivateKey(mSSL.get(), key)
- && 1 == SSL_check_private_key(mSSL.get());
- }
-#endif
-
return 1 == SSL_use_PrivateKey_file(
mSSL.get(), path.c_str(), SSL_FILETYPE_PEM)
&& 1 == SSL_check_private_key(mSSL.get());
}
bool SSLSocket::useTrustedCertificates(const std::string &path) {
-#ifdef TARGET_ANDROID_DEVICE
- std::string name;
- if (isResourcePath(path, &name)) {
- std::vector<uint8_t> data;
- if (!getCertificateOrKey(name, &data)) {
- return false;
- }
-
- std::unique_ptr<BIO, std::function<void(BIO *)>> cbio(
- BIO_new_mem_buf(data.data(), data.size()), BIO_free);
-
- // Shamelessly stolen from
- // https://stackoverflow.com/questions/3810058/
- // read-certificate-files-from-memory-instead-of-a-file-using-openssl
-
- X509_STORE *cts = SSL_CTX_get_cert_store(mCtx.get());
-
- if (!cts) {
- return false;
- }
-
- STACK_OF(X509_INFO) *info =
- PEM_X509_INFO_read_bio(cbio.get(), nullptr, nullptr, nullptr);
-
- if (!info) {
- return false;
- }
-
- for (int i = 0; i < sk_X509_INFO_num(info); ++i) {
- X509_INFO *tmp = sk_X509_INFO_value(info, i);
-
- if (tmp->x509) {
- X509_STORE_add_cert(cts, tmp->x509);
- }
-
- if (tmp->crl) {
- X509_STORE_add_crl(cts, tmp->crl);
- }
- }
-
- sk_X509_INFO_pop_free(info, X509_INFO_free);
-
- return true;
- }
-#endif
-
return 1 == SSL_CTX_load_verify_locations(
mCtx.get(),
path.c_str(),
diff --git a/host/frontend/gcastv2/libandroid/ADebug.cpp b/host/frontend/gcastv2/libandroid/ADebug.cpp
deleted file mode 100644
index fae0970..0000000
--- a/host/frontend/gcastv2/libandroid/ADebug.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-
-#include <media/stagefright/foundation/ADebug.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#ifdef ANDROID
-#include <cutils/log.h>
-#endif
-
-namespace android {
-
-Logger::Logger(LogType type)
- : mLogType(type) {
- switch (mLogType) {
- case VERBOSE:
- mMessage = "V ";
- break;
- case INFO:
- mMessage = "I ";
- break;
- case WARNING:
- mMessage = "W ";
- break;
- case ERROR:
- mMessage = "E ";
- break;
- case FATAL:
- mMessage = "F ";
- break;
-
- default:
- break;
- }
-}
-
-Logger::~Logger() {
- mMessage.append("\n");
-
-#if defined(TARGET_ANDROID_DEVICE)
- if (mLogType == VERBOSE) {
- return;
- }
-
- LOG_PRI(ANDROID_LOG_INFO, "ADebug", "%s", mMessage.c_str());
-#else
- fprintf(stderr, "%s", mMessage.c_str());
- fflush(stderr);
-#endif
-
- if (mLogType == FATAL) {
- abort();
- }
-}
-
-const char *LeafName(const char *s) {
- const char *lastSlash = strrchr(s, '/');
- return lastSlash != NULL ? lastSlash + 1 : s;
-}
-
-} // namespace android
diff --git a/host/frontend/gcastv2/libandroid/ANetworkSession.cpp b/host/frontend/gcastv2/libandroid/ANetworkSession.cpp
deleted file mode 100644
index f422a34..0000000
--- a/host/frontend/gcastv2/libandroid/ANetworkSession.cpp
+++ /dev/null
@@ -1,1410 +0,0 @@
-/*
- * Copyright 2012, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-//#define LOG_NDEBUG 0
-#define LOG_TAG "NetworkSession"
-#include <utils/Log.h>
-
-#include <media/stagefright/foundation/ANetworkSession.h>
-
-#include <arpa/inet.h>
-#include <fcntl.h>
-#include <net/if.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <unistd.h>
-
-#include <media/stagefright/Utils.h>
-#include <media/stagefright/foundation/ABuffer.h>
-#include <media/stagefright/foundation/ADebug.h>
-#include <media/stagefright/foundation/AMessage.h>
-#include <media/stagefright/foundation/hexdump.h>
-#include <media/stagefright/foundation/ParsedMessage.h>
-
-#include <list>
-
-namespace android {
-
-static const size_t kMaxUDPSize = 1500;
-static const int32_t kMaxUDPRetries = 200;
-
-struct ANetworkSession::NetworkThread : public Thread {
- NetworkThread(ANetworkSession *session);
-
-protected:
- virtual ~NetworkThread();
-
-private:
- ANetworkSession *mSession;
-
- virtual bool threadLoop();
-
- DISALLOW_EVIL_CONSTRUCTORS(NetworkThread);
-};
-
-struct ANetworkSession::Session : public RefBase {
- enum Mode {
- MODE_RTSP,
- MODE_DATAGRAM,
- MODE_WEBSOCKET,
- };
-
- enum State {
- CONNECTING,
- CONNECTED,
- LISTENING_RTSP,
- LISTENING_TCP_DGRAMS,
- DATAGRAM,
- };
-
- Session(int32_t sessionID,
- State state,
- int s,
- const sp<AMessage> ¬ify);
-
- int32_t sessionID() const;
- int socket() const;
- sp<AMessage> getNotificationMessage() const;
-
- bool isRTSPServer() const;
- bool isTCPDatagramServer() const;
-
- bool wantsToRead();
- bool wantsToWrite();
-
- status_t readMore();
- status_t writeMore();
-
- status_t sendRequest(
- const void *data, ssize_t size, bool timeValid, int64_t timeUs);
-
- void setMode(Mode mode);
-
- status_t switchToWebSocketMode();
-
-protected:
- virtual ~Session();
-
-private:
- enum {
- FRAGMENT_FLAG_TIME_VALID = 1,
- };
- struct Fragment {
- uint32_t mFlags;
- int64_t mTimeUs;
- sp<ABuffer> mBuffer;
- };
-
- int32_t mSessionID;
- State mState;
- Mode mMode;
- int mSocket;
- sp<AMessage> mNotify;
- bool mSawReceiveFailure, mSawSendFailure;
- int32_t mUDPRetries;
-
- std::list<Fragment> mOutFragments;
-
- std::string mInBuffer;
-
- int64_t mLastStallReportUs;
-
- void notifyError(bool send, status_t err, const char *detail);
- void notify(NotificationReason reason);
-
- void dumpFragmentStats(const Fragment &frag);
-
- DISALLOW_EVIL_CONSTRUCTORS(Session);
-};
-////////////////////////////////////////////////////////////////////////////////
-
-ANetworkSession::NetworkThread::NetworkThread(ANetworkSession *session)
- : mSession(session) {
-}
-
-ANetworkSession::NetworkThread::~NetworkThread() {
-}
-
-bool ANetworkSession::NetworkThread::threadLoop() {
- mSession->threadLoop();
-
- return true;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-ANetworkSession::Session::Session(
- int32_t sessionID,
- State state,
- int s,
- const sp<AMessage> ¬ify)
- : mSessionID(sessionID),
- mState(state),
- mMode(MODE_DATAGRAM),
- mSocket(s),
- mNotify(notify),
- mSawReceiveFailure(false),
- mSawSendFailure(false),
- mUDPRetries(kMaxUDPRetries),
- mLastStallReportUs(-1ll) {
- if (mState == CONNECTED) {
- struct sockaddr_in localAddr;
- socklen_t localAddrLen = sizeof(localAddr);
-
- int res = getsockname(
- mSocket, (struct sockaddr *)&localAddr, &localAddrLen);
- CHECK_GE(res, 0);
-
- struct sockaddr_in remoteAddr;
- socklen_t remoteAddrLen = sizeof(remoteAddr);
-
- res = getpeername(
- mSocket, (struct sockaddr *)&remoteAddr, &remoteAddrLen);
- CHECK_GE(res, 0);
-
- in_addr_t addr = ntohl(localAddr.sin_addr.s_addr);
- std::string localAddrString = StringPrintf(
- "%d.%d.%d.%d",
- (addr >> 24),
- (addr >> 16) & 0xff,
- (addr >> 8) & 0xff,
- addr & 0xff);
-
- addr = ntohl(remoteAddr.sin_addr.s_addr);
- std::string remoteAddrString = StringPrintf(
- "%d.%d.%d.%d",
- (addr >> 24),
- (addr >> 16) & 0xff,
- (addr >> 8) & 0xff,
- addr & 0xff);
-
- sp<AMessage> msg = mNotify->dup();
- msg->setInt32("sessionID", mSessionID);
- msg->setInt32("reason", kWhatClientConnected);
- msg->setString("server-ip", localAddrString.c_str());
- msg->setInt32("server-port", ntohs(localAddr.sin_port));
- msg->setString("client-ip", remoteAddrString.c_str());
- msg->setInt32("client-port", ntohs(remoteAddr.sin_port));
- msg->post();
- }
-}
-
-ANetworkSession::Session::~Session() {
- ALOGV("Session %d gone", mSessionID);
-
- close(mSocket);
- mSocket = -1;
-}
-
-int32_t ANetworkSession::Session::sessionID() const {
- return mSessionID;
-}
-
-int ANetworkSession::Session::socket() const {
- return mSocket;
-}
-
-void ANetworkSession::Session::setMode(Mode mode) {
- mMode = mode;
-}
-
-status_t ANetworkSession::Session::switchToWebSocketMode() {
- if (mState != CONNECTED || mMode != MODE_RTSP) {
- return INVALID_OPERATION;
- }
-
- mMode = MODE_WEBSOCKET;
-
- return OK;
-}
-
-sp<AMessage> ANetworkSession::Session::getNotificationMessage() const {
- return mNotify;
-}
-
-bool ANetworkSession::Session::isRTSPServer() const {
- return mState == LISTENING_RTSP;
-}
-
-bool ANetworkSession::Session::isTCPDatagramServer() const {
- return mState == LISTENING_TCP_DGRAMS;
-}
-
-bool ANetworkSession::Session::wantsToRead() {
- return !mSawReceiveFailure && mState != CONNECTING;
-}
-
-bool ANetworkSession::Session::wantsToWrite() {
- return !mSawSendFailure
- && (mState == CONNECTING
- || (mState == CONNECTED && !mOutFragments.empty())
- || (mState == DATAGRAM && !mOutFragments.empty()));
-}
-
-status_t ANetworkSession::Session::readMore() {
- if (mState == DATAGRAM) {
- CHECK_EQ(mMode, MODE_DATAGRAM);
-
- status_t err;
- do {
- sp<ABuffer> buf = new ABuffer(kMaxUDPSize);
-
- struct sockaddr_in remoteAddr;
- socklen_t remoteAddrLen = sizeof(remoteAddr);
-
- ssize_t n;
- do {
- n = recvfrom(
- mSocket, buf->data(), buf->capacity(), 0,
- (struct sockaddr *)&remoteAddr, &remoteAddrLen);
- } while (n < 0 && errno == EINTR);
-
- err = OK;
- if (n < 0) {
- err = -errno;
- } else if (n == 0) {
- err = -ECONNRESET;
- } else {
- buf->setRange(0, n);
-
- int64_t nowUs = ALooper::GetNowUs();
- buf->meta()->setInt64("arrivalTimeUs", nowUs);
-
- sp<AMessage> notify = mNotify->dup();
- notify->setInt32("sessionID", mSessionID);
- notify->setInt32("reason", kWhatDatagram);
-
- uint32_t ip = ntohl(remoteAddr.sin_addr.s_addr);
- notify->setString(
- "fromAddr",
- StringPrintf(
- "%u.%u.%u.%u",
- ip >> 24,
- (ip >> 16) & 0xff,
- (ip >> 8) & 0xff,
- ip & 0xff).c_str());
-
- notify->setInt32("fromPort", ntohs(remoteAddr.sin_port));
-
- notify->setBuffer("data", buf);
- notify->post();
- }
- } while (err == OK);
-
- if (err == -EAGAIN) {
- err = OK;
- }
-
- if (err != OK) {
- if (!mUDPRetries) {
- notifyError(false /* send */, err, "Recvfrom failed.");
- mSawReceiveFailure = true;
- } else {
- mUDPRetries--;
- ALOGE("Recvfrom failed, %d/%d retries left",
- mUDPRetries, kMaxUDPRetries);
- err = OK;
- }
- } else {
- mUDPRetries = kMaxUDPRetries;
- }
-
- return err;
- }
-
- char tmp[512];
- ssize_t n;
- do {
- n = recv(mSocket, tmp, sizeof(tmp), 0);
- } while (n < 0 && errno == EINTR);
-
- status_t err = OK;
-
- if (n > 0) {
- mInBuffer.append(tmp, n);
-
-#if 0
- ALOGI("in:");
- hexdump(tmp, n);
-#endif
- } else if (n < 0) {
- err = -errno;
- } else {
- err = -ECONNRESET;
- }
-
- if (mMode == MODE_DATAGRAM) {
- // TCP stream carrying 16-bit length-prefixed datagrams.
-
- while (mInBuffer.size() >= 2) {
- size_t packetSize = U16_AT((const uint8_t *)mInBuffer.c_str());
-
- if (mInBuffer.size() < packetSize + 2) {
- break;
- }
-
- sp<ABuffer> packet = new ABuffer(packetSize);
- memcpy(packet->data(), mInBuffer.c_str() + 2, packetSize);
-
- int64_t nowUs = ALooper::GetNowUs();
- packet->meta()->setInt64("arrivalTimeUs", nowUs);
-
- sp<AMessage> notify = mNotify->dup();
- notify->setInt32("sessionID", mSessionID);
- notify->setInt32("reason", kWhatDatagram);
- notify->setBuffer("data", packet);
- notify->post();
-
- mInBuffer.erase(0, packetSize + 2);
- }
- } else if (mMode == MODE_RTSP) {
- for (;;) {
- size_t length;
-
- if (mInBuffer.size() > 0 && mInBuffer.c_str()[0] == '$') {
- if (mInBuffer.size() < 4) {
- break;
- }
-
- length = U16_AT((const uint8_t *)mInBuffer.c_str() + 2);
-
- if (mInBuffer.size() < 4 + length) {
- break;
- }
-
- sp<AMessage> notify = mNotify->dup();
- notify->setInt32("sessionID", mSessionID);
- notify->setInt32("reason", kWhatBinaryData);
- notify->setInt32("channel", mInBuffer.c_str()[1]);
-
- sp<ABuffer> data = new ABuffer(length);
- memcpy(data->data(), mInBuffer.c_str() + 4, length);
-
- int64_t nowUs = ALooper::GetNowUs();
- data->meta()->setInt64("arrivalTimeUs", nowUs);
-
- notify->setBuffer("data", data);
- notify->post();
-
- mInBuffer.erase(0, 4 + length);
- continue;
- }
-
- sp<ParsedMessage> msg =
- ParsedMessage::Parse(
- mInBuffer.c_str(), mInBuffer.size(), err != OK, &length);
-
- if (msg == NULL) {
- break;
- }
-
- sp<AMessage> notify = mNotify->dup();
- notify->setInt32("sessionID", mSessionID);
- notify->setInt32("reason", kWhatData);
- notify->setObject("data", msg);
- notify->post();
-
-#if 1
- // XXX The (old) dongle sends the wrong content length header on a
- // SET_PARAMETER request that signals a "wfd_idr_request".
- // (17 instead of 19).
- const char *content = msg->getContent();
- if (content
- && !memcmp(content, "wfd_idr_request\r\n", 17)
- && length >= 19
- && mInBuffer.c_str()[length] == '\r'
- && mInBuffer.c_str()[length + 1] == '\n') {
- length += 2;
- }
-#endif
-
- mInBuffer.erase(0, length);
-
- if (err != OK) {
- break;
- }
- }
- } else {
- CHECK_EQ(mMode, MODE_WEBSOCKET);
-
- const uint8_t *data = (const uint8_t *)mInBuffer.c_str();
- // hexdump(data, mInBuffer.size());
-
- while (mInBuffer.size() >= 2) {
- size_t offset = 2;
-
- size_t payloadLen = data[1] & 0x7f;
- if (payloadLen == 126) {
- if (offset + 2 > mInBuffer.size()) {
- break;
- }
-
- payloadLen = U16_AT(&data[offset]);
- offset += 2;
- } else if (payloadLen == 127) {
- if (offset + 8 > mInBuffer.size()) {
- break;
- }
-
- payloadLen = U64_AT(&data[offset]);
-
- offset += 8;
- }
-
- uint32_t mask = 0;
- if (data[1] & 0x80) {
- // MASK==1
- if (offset + 4 > mInBuffer.size()) {
- break;
- }
-
- mask = U32_AT(&data[offset]);
- offset += 4;
- }
-
- if (offset + payloadLen > mInBuffer.size()) {
- break;
- }
-
- // We have the full message.
-
- sp<ABuffer> packet = new ABuffer(payloadLen);
- memcpy(packet->data(), &data[offset], payloadLen);
-
- if (mask != 0) {
- for (size_t i = 0; i < payloadLen; ++i) {
- packet->data()[i] =
- data[offset + i]
- ^ ((mask >> (8 * (3 - (i % 4)))) & 0xff);
- }
- }
-
- sp<AMessage> notify = mNotify->dup();
- notify->setInt32("sessionID", mSessionID);
- notify->setInt32("reason", kWhatWebSocketMessage);
- notify->setBuffer("data", packet);
- notify->setInt32("headerByte", data[0]);
- notify->post();
-
- mInBuffer.erase(0, offset + payloadLen);
- }
- }
-
- if (err != OK) {
- notifyError(false /* send */, err, "Recv failed.");
- mSawReceiveFailure = true;
- }
-
- return err;
-}
-
-void ANetworkSession::Session::dumpFragmentStats(const Fragment & /* frag */) {
-#if 0
- int64_t nowUs = ALooper::GetNowUs();
- int64_t delayMs = (nowUs - frag.mTimeUs) / 1000ll;
-
- static const int64_t kMinDelayMs = 0;
- static const int64_t kMaxDelayMs = 300;
-
- const char *kPattern = "########################################";
- size_t kPatternSize = strlen(kPattern);
-
- int n = (kPatternSize * (delayMs - kMinDelayMs))
- / (kMaxDelayMs - kMinDelayMs);
-
- if (n < 0) {
- n = 0;
- } else if ((size_t)n > kPatternSize) {
- n = kPatternSize;
- }
-
- ALOGI("[%lld]: (%4lld ms) %s\n",
- frag.mTimeUs / 1000,
- delayMs,
- kPattern + kPatternSize - n);
-#endif
-}
-
-status_t ANetworkSession::Session::writeMore() {
- if (mState == DATAGRAM) {
- CHECK(!mOutFragments.empty());
-
- status_t err;
- do {
- const Fragment &frag = *mOutFragments.begin();
- const sp<ABuffer> &datagram = frag.mBuffer;
-
- ssize_t n;
- do {
- n = send(mSocket, datagram->data(), datagram->size(), 0);
- } while (n < 0 && errno == EINTR);
-
- err = OK;
-
- if (n > 0) {
- if (frag.mFlags & FRAGMENT_FLAG_TIME_VALID) {
- dumpFragmentStats(frag);
- }
-
- mOutFragments.erase(mOutFragments.begin());
- } else if (n < 0) {
- err = -errno;
- } else if (n == 0) {
- err = -ECONNRESET;
- }
- } while (err == OK && !mOutFragments.empty());
-
- if (err == -EAGAIN) {
- if (!mOutFragments.empty()) {
- ALOGI("%d datagrams remain queued.", mOutFragments.size());
- }
- err = OK;
- }
-
- if (err != OK) {
- if (!mUDPRetries) {
- notifyError(true /* send */, err, "Send datagram failed.");
- mSawSendFailure = true;
- } else {
- mUDPRetries--;
- ALOGE("Send datagram failed, %d/%d retries left",
- mUDPRetries, kMaxUDPRetries);
- err = OK;
- }
- } else {
- mUDPRetries = kMaxUDPRetries;
- }
-
- return err;
- }
-
- if (mState == CONNECTING) {
- int err;
- socklen_t optionLen = sizeof(err);
- CHECK_EQ(getsockopt(mSocket, SOL_SOCKET, SO_ERROR, &err, &optionLen), 0);
- CHECK_EQ(optionLen, (socklen_t)sizeof(err));
-
- if (err != 0) {
- notifyError(kWhatError, -err, "Connection failed");
- mSawSendFailure = true;
-
- return -err;
- }
-
- mState = CONNECTED;
- notify(kWhatConnected);
-
- return OK;
- }
-
- CHECK_EQ(mState, CONNECTED);
- CHECK(!mOutFragments.empty());
-
- ssize_t n = 0;
- while (!mOutFragments.empty()) {
- const Fragment &frag = *mOutFragments.begin();
-
- do {
- n = send(mSocket, frag.mBuffer->data(), frag.mBuffer->size(), 0);
- } while (n < 0 && errno == EINTR);
-
- if (n <= 0) {
- break;
- }
-
- frag.mBuffer->setRange(
- frag.mBuffer->offset() + n, frag.mBuffer->size() - n);
-
- if (frag.mBuffer->size() > 0) {
- break;
- }
-
- if (frag.mFlags & FRAGMENT_FLAG_TIME_VALID) {
- dumpFragmentStats(frag);
- }
-
- mOutFragments.erase(mOutFragments.begin());
- }
-
- status_t err = OK;
-
- if (n < 0) {
- err = -errno;
- } else if (n == 0) {
- err = -ECONNRESET;
- }
-
- if (err != OK) {
- notifyError(true /* send */, err, "Send failed.");
- mSawSendFailure = true;
- }
-
-#if 0
- int numBytesQueued;
- int res = ioctl(mSocket, SIOCOUTQ, &numBytesQueued);
- if (res == 0 && numBytesQueued > 50 * 1024) {
- if (numBytesQueued > 409600) {
- ALOGW("!!! numBytesQueued = %d", numBytesQueued);
- }
-
- int64_t nowUs = ALooper::GetNowUs();
-
- if (mLastStallReportUs < 0ll
- || nowUs > mLastStallReportUs + 100000ll) {
- sp<AMessage> msg = mNotify->dup();
- msg->setInt32("sessionID", mSessionID);
- msg->setInt32("reason", kWhatNetworkStall);
- msg->setSize("numBytesQueued", numBytesQueued);
- msg->post();
-
- mLastStallReportUs = nowUs;
- }
- }
-#endif
-
- return err;
-}
-
-status_t ANetworkSession::Session::sendRequest(
- const void *data, ssize_t size, bool timeValid, int64_t timeUs) {
- CHECK(mState == CONNECTED || mState == DATAGRAM);
-
- if (size < 0) {
- size = strlen((const char *)data);
- }
-
- if (size == 0) {
- return OK;
- }
-
- sp<ABuffer> buffer;
-
- if (mState == CONNECTED && mMode == MODE_DATAGRAM) {
- CHECK_LE(size, 65535);
-
- buffer = new ABuffer(size + 2);
- buffer->data()[0] = size >> 8;
- buffer->data()[1] = size & 0xff;
- memcpy(buffer->data() + 2, data, size);
- } else if (mState == CONNECTED && mMode == MODE_WEBSOCKET) {
- static const bool kUseMask = false; // Chromium doesn't like it.
-
- size_t numHeaderBytes = 2 + (kUseMask ? 4 : 0);
- if (size > 65535) {
- numHeaderBytes += 8;
- } else if (size > 125) {
- numHeaderBytes += 2;
- }
-
- buffer = new ABuffer(numHeaderBytes + size);
- buffer->data()[0] = 0x81; // FIN==1 | opcode=1 (text)
- buffer->data()[1] = kUseMask ? 0x80 : 0x00;
-
- if (size > 65535) {
- buffer->data()[1] |= 127;
- buffer->data()[2] = 0x00;
- buffer->data()[3] = 0x00;
- buffer->data()[4] = 0x00;
- buffer->data()[5] = 0x00;
- buffer->data()[6] = (size >> 24) & 0xff;
- buffer->data()[7] = (size >> 16) & 0xff;
- buffer->data()[8] = (size >> 8) & 0xff;
- buffer->data()[9] = size & 0xff;
- } else if (size > 125) {
- buffer->data()[1] |= 126;
- buffer->data()[2] = (size >> 8) & 0xff;
- buffer->data()[3] = size & 0xff;
- } else {
- buffer->data()[1] |= size;
- }
-
- if (kUseMask) {
- uint32_t mask = rand();
-
- buffer->data()[numHeaderBytes - 4] = (mask >> 24) & 0xff;
- buffer->data()[numHeaderBytes - 3] = (mask >> 16) & 0xff;
- buffer->data()[numHeaderBytes - 2] = (mask >> 8) & 0xff;
- buffer->data()[numHeaderBytes - 1] = mask & 0xff;
-
- for (size_t i = 0; i < (size_t)size; ++i) {
- buffer->data()[numHeaderBytes + i] =
- ((const uint8_t *)data)[i]
- ^ ((mask >> (8 * (3 - (i % 4)))) & 0xff);
- }
- } else {
- memcpy(buffer->data() + numHeaderBytes, data, size);
- }
- } else {
- buffer = new ABuffer(size);
- memcpy(buffer->data(), data, size);
- }
-
- Fragment frag;
-
- frag.mFlags = 0;
- if (timeValid) {
- frag.mFlags = FRAGMENT_FLAG_TIME_VALID;
- frag.mTimeUs = timeUs;
- }
-
- frag.mBuffer = buffer;
-
- mOutFragments.push_back(frag);
-
- return OK;
-}
-
-void ANetworkSession::Session::notifyError(
- bool send, status_t err, const char *detail) {
- sp<AMessage> msg = mNotify->dup();
- msg->setInt32("sessionID", mSessionID);
- msg->setInt32("reason", kWhatError);
- msg->setInt32("send", send);
- msg->setInt32("err", err);
- msg->setString("detail", detail);
- msg->post();
-}
-
-void ANetworkSession::Session::notify(NotificationReason reason) {
- sp<AMessage> msg = mNotify->dup();
- msg->setInt32("sessionID", mSessionID);
- msg->setInt32("reason", reason);
- msg->post();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-ANetworkSession::ANetworkSession()
- : mNextSessionID(1) {
- mPipeFd[0] = mPipeFd[1] = -1;
-}
-
-ANetworkSession::~ANetworkSession() {
- stop();
-}
-
-status_t ANetworkSession::start() {
- if (mThread != NULL) {
- return INVALID_OPERATION;
- }
-
- int res = pipe(mPipeFd);
- if (res != 0) {
- mPipeFd[0] = mPipeFd[1] = -1;
- return -errno;
- }
-
- mThread = new NetworkThread(this);
-
- status_t err = mThread->run("ANetworkSession");
-
- if (err != OK) {
- mThread.clear();
-
- close(mPipeFd[0]);
- close(mPipeFd[1]);
- mPipeFd[0] = mPipeFd[1] = -1;
-
- return err;
- }
-
- return OK;
-}
-
-status_t ANetworkSession::stop() {
- if (mThread == NULL) {
- return INVALID_OPERATION;
- }
-
- mThread->requestExit();
- interrupt();
- mThread->requestExitAndWait();
-
- mThread.clear();
-
- close(mPipeFd[0]);
- close(mPipeFd[1]);
- mPipeFd[0] = mPipeFd[1] = -1;
-
- return OK;
-}
-
-status_t ANetworkSession::createRTSPClient(
- const char *host, unsigned port, const sp<AMessage> ¬ify,
- int32_t *sessionID) {
- return createClientOrServer(
- kModeCreateRTSPClient,
- NULL /* addr */,
- 0 /* port */,
- host,
- port,
- notify,
- sessionID);
-}
-
-status_t ANetworkSession::createRTSPServer(
- const struct in_addr &addr, unsigned port,
- const sp<AMessage> ¬ify, int32_t *sessionID) {
- return createClientOrServer(
- kModeCreateRTSPServer,
- &addr,
- port,
- NULL /* remoteHost */,
- 0 /* remotePort */,
- notify,
- sessionID);
-}
-
-status_t ANetworkSession::createUDPSession(
- unsigned localPort, const sp<AMessage> ¬ify, int32_t *sessionID) {
- return createUDPSession(localPort, NULL, 0, notify, sessionID);
-}
-
-status_t ANetworkSession::createUDPSession(
- unsigned localPort,
- const char *remoteHost,
- unsigned remotePort,
- const sp<AMessage> ¬ify,
- int32_t *sessionID) {
- return createClientOrServer(
- kModeCreateUDPSession,
- NULL /* addr */,
- localPort,
- remoteHost,
- remotePort,
- notify,
- sessionID);
-}
-
-status_t ANetworkSession::createTCPDatagramSession(
- const struct in_addr &addr, unsigned port,
- const sp<AMessage> ¬ify, int32_t *sessionID) {
- return createClientOrServer(
- kModeCreateTCPDatagramSessionPassive,
- &addr,
- port,
- NULL /* remoteHost */,
- 0 /* remotePort */,
- notify,
- sessionID);
-}
-
-status_t ANetworkSession::createTCPDatagramSession(
- unsigned localPort,
- const char *remoteHost,
- unsigned remotePort,
- const sp<AMessage> ¬ify,
- int32_t *sessionID) {
- return createClientOrServer(
- kModeCreateTCPDatagramSessionActive,
- NULL /* addr */,
- localPort,
- remoteHost,
- remotePort,
- notify,
- sessionID);
-}
-
-status_t ANetworkSession::destroySession(int32_t sessionID) {
- Mutex::Autolock autoLock(mLock);
-
- auto it = mSessions.find(sessionID);
-
- if (it == mSessions.end()) {
- return -ENOENT;
- }
-
- mSessions.erase(it);
-
- interrupt();
-
- return OK;
-}
-
-// static
-status_t ANetworkSession::MakeSocketNonBlocking(int s) {
- int flags = fcntl(s, F_GETFL, 0);
- if (flags < 0) {
- flags = 0;
- }
-
- int res = fcntl(s, F_SETFL, flags | O_NONBLOCK);
- if (res < 0) {
- return -errno;
- }
-
- return OK;
-}
-
-status_t ANetworkSession::createClientOrServer(
- Mode mode,
- const struct in_addr *localAddr,
- unsigned port,
- const char *remoteHost,
- unsigned remotePort,
- const sp<AMessage> ¬ify,
- int32_t *sessionID) {
- Mutex::Autolock autoLock(mLock);
-
- *sessionID = 0;
- status_t err = OK;
- int s, res;
- sp<Session> session;
-
- s = socket(
- AF_INET,
- (mode == kModeCreateUDPSession) ? SOCK_DGRAM : SOCK_STREAM,
- 0);
-
- if (s < 0) {
- err = -errno;
- goto bail;
- }
-
- if (mode == kModeCreateRTSPServer
- || mode == kModeCreateTCPDatagramSessionPassive) {
- const int yes = 1;
- res = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
-
- if (res < 0) {
- err = -errno;
- goto bail2;
- }
- }
-
- if (mode == kModeCreateUDPSession) {
- int size = 256 * 1024;
-
- res = setsockopt(s, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size));
-
- if (res < 0) {
- err = -errno;
- goto bail2;
- }
-
- res = setsockopt(s, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size));
-
- if (res < 0) {
- err = -errno;
- goto bail2;
- }
- } else if (mode == kModeCreateTCPDatagramSessionActive) {
-#if 0
- int flag = 1;
- res = setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag));
-
- if (res < 0) {
- err = -errno;
- goto bail2;
- }
-#endif
-
- int tos = 224; // VOICE
- res = setsockopt(s, IPPROTO_IP, IP_TOS, &tos, sizeof(tos));
-
- if (res < 0) {
- err = -errno;
- goto bail2;
- }
- }
-
- err = MakeSocketNonBlocking(s);
-
- if (err != OK) {
- goto bail2;
- }
-
- struct sockaddr_in addr;
- memset(addr.sin_zero, 0, sizeof(addr.sin_zero));
- addr.sin_family = AF_INET;
-
- if (mode == kModeCreateRTSPClient
- || mode == kModeCreateTCPDatagramSessionActive) {
- struct hostent *ent= gethostbyname(remoteHost);
- if (ent == NULL) {
- err = -h_errno;
- goto bail2;
- }
-
- addr.sin_addr.s_addr = *(in_addr_t *)ent->h_addr;
- addr.sin_port = htons(remotePort);
- } else if (localAddr != NULL) {
- addr.sin_addr = *localAddr;
- addr.sin_port = htons(port);
- } else {
- addr.sin_addr.s_addr = htonl(INADDR_ANY);
- addr.sin_port = htons(port);
- }
-
- if (mode == kModeCreateRTSPClient
- || mode == kModeCreateTCPDatagramSessionActive) {
- in_addr_t x = ntohl(addr.sin_addr.s_addr);
- ALOGI("connecting socket %d to %d.%d.%d.%d:%d",
- s,
- (x >> 24),
- (x >> 16) & 0xff,
- (x >> 8) & 0xff,
- x & 0xff,
- ntohs(addr.sin_port));
-
- res = connect(s, (const struct sockaddr *)&addr, sizeof(addr));
-
- CHECK_LT(res, 0);
- if (errno == EINPROGRESS) {
- res = 0;
- }
- } else {
- res = bind(s, (const struct sockaddr *)&addr, sizeof(addr));
-
- if (res == 0) {
- if (mode == kModeCreateRTSPServer
- || mode == kModeCreateTCPDatagramSessionPassive) {
- res = listen(s, 4);
- } else {
- CHECK_EQ(mode, kModeCreateUDPSession);
-
- if (remoteHost != NULL) {
- struct sockaddr_in remoteAddr;
- memset(remoteAddr.sin_zero, 0, sizeof(remoteAddr.sin_zero));
- remoteAddr.sin_family = AF_INET;
- remoteAddr.sin_port = htons(remotePort);
-
- struct hostent *ent= gethostbyname(remoteHost);
- if (ent == NULL) {
- err = -h_errno;
- goto bail2;
- }
-
- remoteAddr.sin_addr.s_addr = *(in_addr_t *)ent->h_addr;
-
- res = connect(
- s,
- (const struct sockaddr *)&remoteAddr,
- sizeof(remoteAddr));
- }
- }
- }
- }
-
- if (res < 0) {
- err = -errno;
- goto bail2;
- }
-
- Session::State state;
- switch (mode) {
- case kModeCreateRTSPClient:
- state = Session::CONNECTING;
- break;
-
- case kModeCreateTCPDatagramSessionActive:
- state = Session::CONNECTING;
- break;
-
- case kModeCreateTCPDatagramSessionPassive:
- state = Session::LISTENING_TCP_DGRAMS;
- break;
-
- case kModeCreateRTSPServer:
- state = Session::LISTENING_RTSP;
- break;
-
- default:
- CHECK_EQ(mode, kModeCreateUDPSession);
- state = Session::DATAGRAM;
- break;
- }
-
- session = new Session(
- mNextSessionID++,
- state,
- s,
- notify);
-
- if (mode == kModeCreateTCPDatagramSessionActive) {
- session->setMode(Session::MODE_DATAGRAM);
- } else if (mode == kModeCreateRTSPClient) {
- session->setMode(Session::MODE_RTSP);
- }
-
- mSessions[session->sessionID()] = session;
-
- interrupt();
-
- *sessionID = session->sessionID();
-
- goto bail;
-
-bail2:
- close(s);
- s = -1;
-
-bail:
- return err;
-}
-
-status_t ANetworkSession::connectUDPSession(
- int32_t sessionID, const char *remoteHost, unsigned remotePort) {
- Mutex::Autolock autoLock(mLock);
-
- auto it = mSessions.find(sessionID);
-
- if (it == mSessions.end()) {
- return -ENOENT;
- }
-
- const sp<Session> session = it->second;
- int s = session->socket();
-
- struct sockaddr_in remoteAddr;
- memset(remoteAddr.sin_zero, 0, sizeof(remoteAddr.sin_zero));
- remoteAddr.sin_family = AF_INET;
- remoteAddr.sin_port = htons(remotePort);
-
- status_t err = OK;
- struct hostent *ent = gethostbyname(remoteHost);
- if (ent == NULL) {
- err = -h_errno;
- } else {
- remoteAddr.sin_addr.s_addr = *(in_addr_t *)ent->h_addr;
-
- int res = connect(
- s,
- (const struct sockaddr *)&remoteAddr,
- sizeof(remoteAddr));
-
- if (res < 0) {
- err = -errno;
- }
- }
-
- return err;
-}
-
-status_t ANetworkSession::sendRequest(
- int32_t sessionID, const void *data, ssize_t size,
- bool timeValid, int64_t timeUs) {
- Mutex::Autolock autoLock(mLock);
-
- auto it = mSessions.find(sessionID);
-
- if (it == mSessions.end()) {
- return -ENOENT;
- }
-
- const sp<Session> session = it->second;
-
- status_t err = session->sendRequest(data, size, timeValid, timeUs);
-
- interrupt();
-
- return err;
-}
-
-status_t ANetworkSession::switchToWebSocketMode(int32_t sessionID) {
- Mutex::Autolock autoLock(mLock);
-
- auto it = mSessions.find(sessionID);
-
- if (it == mSessions.end()) {
- return -ENOENT;
- }
-
- const sp<Session> session = it->second;
- return session->switchToWebSocketMode();
-}
-
-void ANetworkSession::interrupt() {
- static const char dummy = 0;
-
- ssize_t n;
- do {
- n = write(mPipeFd[1], &dummy, 1);
- } while (n < 0 && errno == EINTR);
-
- if (n < 0) {
- ALOGW("Error writing to pipe (%s)", strerror(errno));
- }
-}
-
-void ANetworkSession::threadLoop() {
- fd_set rs, ws;
- FD_ZERO(&rs);
- FD_ZERO(&ws);
-
- FD_SET(mPipeFd[0], &rs);
- int maxFd = mPipeFd[0];
-
- {
- Mutex::Autolock autoLock(mLock);
-
- for (const auto &pair : mSessions) {
- const sp<Session> &session = pair.second;
-
- int s = session->socket();
-
- if (s < 0) {
- continue;
- }
-
- if (session->wantsToRead()) {
- FD_SET(s, &rs);
- if (s > maxFd) {
- maxFd = s;
- }
- }
-
- if (session->wantsToWrite()) {
- FD_SET(s, &ws);
- if (s > maxFd) {
- maxFd = s;
- }
- }
- }
- }
-
- int res = select(maxFd + 1, &rs, &ws, NULL, NULL /* tv */);
-
- if (res == 0) {
- return;
- }
-
- if (res < 0) {
- if (errno == EINTR) {
- return;
- }
-
- ALOGE("select failed w/ error %d (%s)", errno, strerror(errno));
- return;
- }
-
- if (FD_ISSET(mPipeFd[0], &rs)) {
- char c;
- ssize_t n;
- do {
- n = read(mPipeFd[0], &c, 1);
- } while (n < 0 && errno == EINTR);
-
- if (n < 0) {
- ALOGW("Error reading from pipe (%s)", strerror(errno));
- }
-
- --res;
- }
-
- {
- Mutex::Autolock autoLock(mLock);
-
- std::list<sp<Session>> sessionsToAdd;
-
- for (const auto &pair : mSessions) {
- if (res <= 0) {
- break;
- }
-
- const sp<Session> &session = pair.second;
-
- int s = session->socket();
-
- if (s < 0) {
- continue;
- }
-
- if (FD_ISSET(s, &rs) || FD_ISSET(s, &ws)) {
- --res;
- }
-
- if (FD_ISSET(s, &rs)) {
- if (session->isRTSPServer() || session->isTCPDatagramServer()) {
- struct sockaddr_in remoteAddr;
- socklen_t remoteAddrLen = sizeof(remoteAddr);
-
- int clientSocket = accept(
- s, (struct sockaddr *)&remoteAddr, &remoteAddrLen);
-
- if (clientSocket >= 0) {
- status_t err = MakeSocketNonBlocking(clientSocket);
-
- if (err != OK) {
- ALOGE("Unable to make client socket non blocking, "
- "failed w/ error %d (%s)",
- err, strerror(-err));
-
- close(clientSocket);
- clientSocket = -1;
- } else {
- in_addr_t addr = ntohl(remoteAddr.sin_addr.s_addr);
-
- ALOGI("incoming connection from %d.%d.%d.%d:%d "
- "(socket %d)",
- (addr >> 24),
- (addr >> 16) & 0xff,
- (addr >> 8) & 0xff,
- addr & 0xff,
- ntohs(remoteAddr.sin_port),
- clientSocket);
-
- sp<Session> clientSession =
- new Session(
- mNextSessionID++,
- Session::CONNECTED,
- clientSocket,
- session->getNotificationMessage());
-
- clientSession->setMode(
- session->isRTSPServer()
- ? Session::MODE_RTSP
- : Session::MODE_DATAGRAM);
-
- sessionsToAdd.push_back(clientSession);
- }
- } else {
- ALOGE("accept returned error %d (%s)",
- errno, strerror(errno));
- }
- } else {
- status_t err = session->readMore();
- if (err != OK) {
- ALOGE("readMore on socket %d failed w/ error %d (%s)",
- s, err, strerror(-err));
- }
- }
- }
-
- if (FD_ISSET(s, &ws)) {
- status_t err = session->writeMore();
- if (err != OK) {
- ALOGE("writeMore on socket %d failed w/ error %d (%s)",
- s, err, strerror(-err));
- }
- }
- }
-
- while (!sessionsToAdd.empty()) {
- sp<Session> session = *sessionsToAdd.begin();
- sessionsToAdd.erase(sessionsToAdd.begin());
-
- mSessions[session->sessionID()] = session;
-
- ALOGI("added clientSession %d", session->sessionID());
- }
- }
-}
-
-} // namespace android
-
diff --git a/host/frontend/gcastv2/libandroid/ATSParser.cpp b/host/frontend/gcastv2/libandroid/ATSParser.cpp
index 2275f5d..ac061bf 100644
--- a/host/frontend/gcastv2/libandroid/ATSParser.cpp
+++ b/host/frontend/gcastv2/libandroid/ATSParser.cpp
@@ -294,9 +294,6 @@
CHECK_GE(infoBytesRemaining - 5, ES_info_length);
-#if 0
- br->skipBits(ES_info_length * 8); // skip descriptors
-#else
unsigned info_bytes_remaining = ES_info_length;
while (info_bytes_remaining >= 2) {
MY_LOGV(" tag = 0x%02x", br->getBits(8));
@@ -311,7 +308,6 @@
info_bytes_remaining -= descLength + 2;
}
CHECK_EQ(info_bytes_remaining, 0u);
-#endif
StreamInfo info;
info.mType = streamType;
@@ -335,22 +331,6 @@
}
if (PIDsChanged) {
-#if 0
- ALOGI("before:");
- for (size_t i = 0; i < mStreams.size(); ++i) {
- sp<Stream> stream = mStreams.editValueAt(i);
-
- ALOGI("PID 0x%08x => type 0x%02x", stream->pid(), stream->type());
- }
-
- ALOGI("after:");
- for (size_t i = 0; i < infos.size(); ++i) {
- StreamInfo &info = infos.editItemAt(i);
-
- ALOGI("PID 0x%08x => type 0x%02x", info.mPID, info.mType);
- }
-#endif
-
// The only case we can recover from is if we have two streams
// and they switched PIDs.
@@ -529,16 +509,6 @@
mBuffer->setRange(0, 0);
mExpectedContinuityCounter = -1;
-#if 0
- // Uncomment this if you'd rather see no corruption whatsoever on
- // screen and suspend updates until we come across another IDR frame.
-
- if (mStreamType == STREAMTYPE_H264) {
- ALOGI("clearing video queue");
- mQueue->clear(true /* clearFormat */);
- }
-#endif
-
return OK;
}
@@ -832,14 +802,6 @@
void ATSParser::Stream::onPayloadData(
unsigned PTS_DTS_flags, uint64_t PTS, uint64_t /* DTS */,
const uint8_t *data, size_t size) {
-#if 0
- ALOGI("payload streamType 0x%02x, PTS = 0x%016llx, dPTS = %lld",
- mStreamType,
- PTS,
- (int64_t)PTS - mPrevPTS);
- mPrevPTS = PTS;
-#endif
-
ALOGV("onPayloadData mStreamType=0x%02x", mStreamType);
int64_t timeUs = 0ll; // no presentation timestamp available.
@@ -1234,15 +1196,6 @@
mSystemTimeUs[mNumPCRs] = ALooper::GetNowUs();
++mNumPCRs;
-
-#if 0
- if (mNumPCRs == 2) {
- double transportRate =
- (mPCRBytes[1] - mPCRBytes[0]) * 27E6 / (mPCR[1] - mPCR[0]);
-
- ALOGV("transportRate = %.2f bytes/sec", transportRate);
- }
-#endif
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/host/frontend/gcastv2/libandroid/Android.bp b/host/frontend/gcastv2/libandroid/Android.bp
index 7c781ef..8e3bfa9 100644
--- a/host/frontend/gcastv2/libandroid/Android.bp
+++ b/host/frontend/gcastv2/libandroid/Android.bp
@@ -22,42 +22,19 @@
"ALooper.cpp",
"ALooperRoster.cpp",
"AMessage.cpp",
- "ANetworkSession.cpp",
"AnotherPacketSource.cpp",
"ATSParser.cpp",
"ESQueue.cpp",
- "FileSource.cpp",
"JSONObject.cpp",
- "KeyStore.cpp",
- "MyScopedByteArray.cpp",
- "MyScopedUTF8String.cpp",
"NuMediaExtractor.cpp",
"Utils.cpp",
"avc_utils.cpp",
- "base64.cpp",
"hexdump.cpp",
"ParsedMessage.cpp",
"RefBase.cpp",
"TSPacketizer.cpp",
],
- target: {
- host: {
- cflags: [
- "-DTARGET_ANDROID",
- ],
- },
- android: {
- cflags: [
- "-DTARGET_ANDROID_DEVICE",
- ],
- srcs: [
- "ADebug.cpp",
- "JavaThread.cpp",
- "MyAndroidRuntime.cpp",
- "MyJNIHelpers.cpp",
- ],
- },
- },
+ defaults: ["cuttlefish_host_only"],
shared_libs: [
"libbase",
],
diff --git a/host/frontend/gcastv2/libandroid/ESQueue.cpp b/host/frontend/gcastv2/libandroid/ESQueue.cpp
index cd50663..2b48e0a 100644
--- a/host/frontend/gcastv2/libandroid/ESQueue.cpp
+++ b/host/frontend/gcastv2/libandroid/ESQueue.cpp
@@ -128,11 +128,6 @@
case H264:
case MPEG_VIDEO:
{
-#if 0
- if (size < 4 || memcmp("\x00\x00\x00\x01", data, 4)) {
- return ERROR_MALFORMED;
- }
-#else
uint8_t *ptr = (uint8_t *)data;
ssize_t startOffset = -1;
@@ -155,17 +150,11 @@
data = &ptr[startOffset];
size -= startOffset;
-#endif
break;
}
case MPEG4_VIDEO:
{
-#if 0
- if (size < 3 || memcmp("\x00\x00\x01", data, 3)) {
- return ERROR_MALFORMED;
- }
-#else
uint8_t *ptr = (uint8_t *)data;
ssize_t startOffset = -1;
@@ -188,7 +177,6 @@
data = &ptr[startOffset];
size -= startOffset;
-#endif
break;
}
@@ -196,11 +184,6 @@
{
uint8_t *ptr = (uint8_t *)data;
-#if 0
- if (size < 2 || ptr[0] != 0xff || (ptr[1] >> 4) != 0x0f) {
- return ERROR_MALFORMED;
- }
-#else
ssize_t startOffset = -1;
for (size_t i = 0; i < size; ++i) {
if (IsSeeminglyValidADTSHeader(&ptr[i], size - i)) {
@@ -220,7 +203,6 @@
data = &ptr[startOffset];
size -= startOffset;
-#endif
break;
}
@@ -287,12 +269,6 @@
info.mTimestampUs = timeUs;
mRangeInfos.push_back(info);
-#if 0
- if (mMode == AAC) {
- ALOGI("size = %d, timeUs = %.2f secs", size, timeUs / 1E6);
- hexdump(data, size);
- }
-#endif
return OK;
}
diff --git a/host/frontend/gcastv2/libandroid/FileSource.cpp b/host/frontend/gcastv2/libandroid/FileSource.cpp
deleted file mode 100644
index 986b4f5..0000000
--- a/host/frontend/gcastv2/libandroid/FileSource.cpp
+++ /dev/null
@@ -1,76 +0,0 @@
-#include <media/stagefright/FileSource.h>
-
-#include <fcntl.h>
-#include <unistd.h>
-
-#ifdef TARGET_IOS
-#include <CoreFoundation/CoreFoundation.h>
-#endif
-
-namespace android {
-
-FileSource::FileSource(const char *path)
- : mFd(-1),
- mInitCheck(NO_INIT) {
-#ifdef TARGET_IOS
- CFBundleRef mainBundle = CFBundleGetMainBundle();
-
- CFStringRef pathRef =
- CFStringCreateWithCString(kCFAllocatorDefault, path, kCFStringEncodingUTF8);
-
- CFURLRef url = CFBundleCopyResourceURL(mainBundle, pathRef, NULL, NULL);
-
- CFRelease(pathRef);
- pathRef = nullptr;
-
- pathRef = CFURLCopyPath(url);
-
- CFRelease(url);
- url = nullptr;
-
- char fullPath[256];
- CFStringGetCString(
- pathRef, fullPath, sizeof(fullPath), kCFStringEncodingUTF8);
-
- CFRelease(pathRef);
- pathRef = nullptr;
-
- path = fullPath;
-#endif
-
- mFd = open(path, O_RDONLY);
- mInitCheck = (mFd >= 0) ? OK : -errno;
-}
-
-FileSource::~FileSource() {
- if (mFd >= 0) {
- close(mFd);
- mFd = -1;
- }
-}
-
-status_t FileSource::initCheck() const {
- return mInitCheck;
-}
-
-status_t FileSource::getSize(off_t *size) const {
- *size = lseek(mFd, 0, SEEK_END);
- if (*size == -1) {
- return -errno;
- }
-
- return OK;
-}
-
-ssize_t FileSource::readAt(off_t offset, void *data, size_t size) {
- ssize_t n = pread(mFd, data, size, offset);
-
- if (n == -1) {
- return -errno;
- }
-
- return n;
-}
-
-} // namespace android
-
diff --git a/host/frontend/gcastv2/libandroid/JavaThread.cpp b/host/frontend/gcastv2/libandroid/JavaThread.cpp
deleted file mode 100644
index e35846f..0000000
--- a/host/frontend/gcastv2/libandroid/JavaThread.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-#include <helpers/JavaThread.h>
-
-#include <helpers/MyAndroidRuntime.h>
-#include <media/stagefright/foundation/ADebug.h>
-
-namespace android {
-
-void javaAttachThread() {
- JavaVMAttachArgs args;
- args.version = JNI_VERSION_1_4;
- args.name = (char *)"JavaThread";
- args.group = nullptr;
-
- JavaVM *vm = MyAndroidRuntime::getJavaVM();
- CHECK(vm);
-
- JNIEnv *env;
- jint result = vm->AttachCurrentThread(&env, (void *)&args);
- CHECK_EQ(result, JNI_OK);
-}
-
-void javaDetachThread() {
- JavaVM *vm = MyAndroidRuntime::getJavaVM();
- CHECK(vm);
-
- CHECK_EQ(vm->DetachCurrentThread(), JNI_OK);
-}
-
-} // namespace android
-
diff --git a/host/frontend/gcastv2/libandroid/KeyStore.cpp b/host/frontend/gcastv2/libandroid/KeyStore.cpp
deleted file mode 100644
index 83ec9cd..0000000
--- a/host/frontend/gcastv2/libandroid/KeyStore.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-#include <utils/KeyStore.h>
-
-#include <unordered_map>
-#include <mutex>
-
-static std::unordered_map<std::string, std::vector<uint8_t>> gCertStore;
-static std::mutex gCertStoreLock;
-
-void setCertificateOrKey(
- const std::string &name, const void *_data, size_t size) {
-
- const uint8_t *data = static_cast<const uint8_t *>(_data);
-
- std::lock_guard autoLock(gCertStoreLock);
- gCertStore[name] = std::vector<uint8_t>(data, &data[size]);
-}
-
-bool getCertificateOrKey(
- const std::string &name, std::vector<uint8_t> *data) {
- std::lock_guard autoLock(gCertStoreLock);
-
- auto it = gCertStore.find(name);
- if (it == gCertStore.end()) {
- return false;
- }
-
- *data = it->second;
-
- return true;
-}
diff --git a/host/frontend/gcastv2/libandroid/MyAndroidRuntime.cpp b/host/frontend/gcastv2/libandroid/MyAndroidRuntime.cpp
deleted file mode 100644
index ae111b0..0000000
--- a/host/frontend/gcastv2/libandroid/MyAndroidRuntime.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-#include <helpers/MyAndroidRuntime.h>
-
-namespace android {
-
-static JavaVM *gVM;
-
-// static
-void MyAndroidRuntime::setJavaVM(JavaVM *vm) {
- gVM = vm;
-}
-
-// static
-JavaVM *MyAndroidRuntime::getJavaVM() {
- return gVM;
-}
-
-// static
-JNIEnv *MyAndroidRuntime::getJNIEnv() {
- JNIEnv *env;
- if (gVM->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
- return nullptr;
- }
-
- return env;
-}
-
-} // namespace android
-
diff --git a/host/frontend/gcastv2/libandroid/MyJNIHelpers.cpp b/host/frontend/gcastv2/libandroid/MyJNIHelpers.cpp
deleted file mode 100644
index f1ed0fe..0000000
--- a/host/frontend/gcastv2/libandroid/MyJNIHelpers.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-#include <helpers/MyJNIHelpers.h>
-
-#include <helpers/MyScopedLocalRef.h>
-#include <media/stagefright/foundation/ADebug.h>
-
-namespace android {
-
-void jniThrowException(
- JNIEnv *env, const char *className, const char *msg) {
- MyScopedLocalRef<jclass> clazz(env, env->FindClass(className));
- CHECK(clazz.get() != nullptr);
-
- CHECK_EQ(env->ThrowNew(clazz.get(), msg), JNI_OK);
-}
-
-int jniRegisterNativeMethods(
- JNIEnv *env,
- const char *className,
- const JNINativeMethod *methods,
- size_t numMethods) {
- MyScopedLocalRef<jclass> clazz(env, env->FindClass(className));
- CHECK(clazz.get() != nullptr);
-
- CHECK_GE(env->RegisterNatives(clazz.get(), methods, numMethods), 0);
-
- return 0;
-}
-
-} // namespaced android
-
diff --git a/host/frontend/gcastv2/libandroid/MyScopedByteArray.cpp b/host/frontend/gcastv2/libandroid/MyScopedByteArray.cpp
deleted file mode 100644
index 6f31d38..0000000
--- a/host/frontend/gcastv2/libandroid/MyScopedByteArray.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-#include <helpers/MyScopedByteArray.h>
-
-namespace android {
-
-MyScopedByteArray::MyScopedByteArray(JNIEnv *env, jbyteArray arrayObj)
- : mEnv(env),
- mArrayObj(arrayObj),
- mElements(nullptr),
- mSize(0) {
- if (mArrayObj) {
- mElements = env->GetByteArrayElements(mArrayObj, nullptr /* isCopy */);
- mSize = env->GetArrayLength(mArrayObj);
- }
-}
-
-MyScopedByteArray::~MyScopedByteArray() {
- if (mArrayObj) {
- mEnv->ReleaseByteArrayElements(mArrayObj, mElements, 0 /* mode */);
- }
-}
-
-const jbyte *MyScopedByteArray::data() const {
- return mElements;
-}
-
-jsize MyScopedByteArray::size() const {
- return mSize;
-}
-
-} // namespace android
-
diff --git a/host/frontend/gcastv2/libandroid/MyScopedUTF8String.cpp b/host/frontend/gcastv2/libandroid/MyScopedUTF8String.cpp
deleted file mode 100644
index 2f7e3fe..0000000
--- a/host/frontend/gcastv2/libandroid/MyScopedUTF8String.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-#include <helpers/MyScopedUTF8String.h>
-
-namespace android {
-
-MyScopedUTF8String::MyScopedUTF8String(JNIEnv *env, jstring stringObj)
- : mEnv(env),
- mStringObj(stringObj),
- mData(stringObj ? env->GetStringUTFChars(stringObj, nullptr) : nullptr) {
-}
-
-MyScopedUTF8String::~MyScopedUTF8String() {
- if (mData) {
- mEnv->ReleaseStringUTFChars(mStringObj, mData);
- mData = nullptr;
- }
-}
-
-const char *MyScopedUTF8String::c_str() const {
- return mData;
-}
-
-} // namespace android
diff --git a/host/frontend/gcastv2/libandroid/TSPacketizer.cpp b/host/frontend/gcastv2/libandroid/TSPacketizer.cpp
index f6c4436..ece06fb 100644
--- a/host/frontend/gcastv2/libandroid/TSPacketizer.cpp
+++ b/host/frontend/gcastv2/libandroid/TSPacketizer.cpp
@@ -526,11 +526,7 @@
// reserved = b111111
// program_clock_reference_extension = b?????????
-#if 0
- int64_t nowUs = ALooper::GetNowUs();
-#else
int64_t nowUs = timeUs;
-#endif
uint64_t PCR = nowUs * 27; // PCR based on a 27MHz clock
uint64_t PCR_base = PCR / 300;
diff --git a/host/frontend/gcastv2/libandroid/avc_utils.cpp b/host/frontend/gcastv2/libandroid/avc_utils.cpp
index 860d045..4dd60e3 100644
--- a/host/frontend/gcastv2/libandroid/avc_utils.cpp
+++ b/host/frontend/gcastv2/libandroid/avc_utils.cpp
@@ -286,11 +286,6 @@
*out++ = picParamSet->size() & 0xff;
memcpy(out, picParamSet->data(), picParamSet->size());
-#if 0
- ALOGI("AVC seq param set");
- hexdump(seqParamSet->data(), seqParamSet->size());
-#endif
-
sp<MetaData> meta = new MetaData;
meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_AVC);
diff --git a/host/frontend/gcastv2/libandroid/base64.cpp b/host/frontend/gcastv2/libandroid/base64.cpp
deleted file mode 100644
index 3ec5410..0000000
--- a/host/frontend/gcastv2/libandroid/base64.cpp
+++ /dev/null
@@ -1,122 +0,0 @@
-#include <media/stagefright/foundation/base64.h>
-
-#include <media/stagefright/foundation/ABuffer.h>
-#include <media/stagefright/foundation/ADebug.h>
-
-namespace android {
-
-sp<ABuffer> decodeBase64(const std::string_view &s) {
- if ((s.size() % 4) != 0) {
- return NULL;
- }
-
- size_t n = s.size();
- size_t padding = 0;
- if (n >= 1 && s[n - 1] == '=') {
- padding = 1;
-
- if (n >= 2 && s[n - 2] == '=') {
- padding = 2;
- }
- }
-
- size_t outLen = 3 * s.size() / 4 - padding;
-
- sp<ABuffer> buffer = new ABuffer(outLen);
-
- uint8_t *out = buffer->data();
- size_t j = 0;
- uint32_t accum = 0;
- for (size_t i = 0; i < n; ++i) {
- char c = s[i];
- unsigned value;
- if (c >= 'A' && c <= 'Z') {
- value = c - 'A';
- } else if (c >= 'a' && c <= 'z') {
- value = 26 + c - 'a';
- } else if (c >= '0' && c <= '9') {
- value = 52 + c - '0';
- } else if (c == '+') {
- value = 62;
- } else if (c == '/') {
- value = 63;
- } else if (c != '=') {
- return NULL;
- } else {
- if (i < n - padding) {
- return NULL;
- }
-
- value = 0;
- }
-
- accum = (accum << 6) | value;
-
- if (((i + 1) % 4) == 0) {
- out[j++] = (accum >> 16);
-
- if (j < outLen) { out[j++] = (accum >> 8) & 0xff; }
- if (j < outLen) { out[j++] = accum & 0xff; }
-
- accum = 0;
- }
- }
-
- return buffer;
-}
-
-static char encode6Bit(unsigned x) {
- if (x <= 25) {
- return 'A' + x;
- } else if (x <= 51) {
- return 'a' + x - 26;
- } else if (x <= 61) {
- return '0' + x - 52;
- } else if (x == 62) {
- return '+';
- } else {
- return '/';
- }
-}
-
-void encodeBase64(const void *_data, size_t size, std::string *out) {
- out->clear();
-
- const uint8_t *data = (const uint8_t *)_data;
-
- size_t i;
- for (i = 0; i < (size / 3) * 3; i += 3) {
- uint8_t x1 = data[i];
- uint8_t x2 = data[i + 1];
- uint8_t x3 = data[i + 2];
-
- out->append(1, encode6Bit(x1 >> 2));
- out->append(1, encode6Bit((x1 << 4 | x2 >> 4) & 0x3f));
- out->append(1, encode6Bit((x2 << 2 | x3 >> 6) & 0x3f));
- out->append(1, encode6Bit(x3 & 0x3f));
- }
- switch (size % 3) {
- case 0:
- break;
- case 2:
- {
- uint8_t x1 = data[i];
- uint8_t x2 = data[i + 1];
- out->append(1, encode6Bit(x1 >> 2));
- out->append(1, encode6Bit((x1 << 4 | x2 >> 4) & 0x3f));
- out->append(1, encode6Bit((x2 << 2) & 0x3f));
- out->append(1, '=');
- break;
- }
- default:
- {
- uint8_t x1 = data[i];
- out->append(1, encode6Bit(x1 >> 2));
- out->append(1, encode6Bit((x1 << 4) & 0x3f));
- out->append("==");
- break;
- }
- }
-}
-
-} // namespace android
diff --git a/host/frontend/gcastv2/libandroid/include/helpers/JavaThread.h b/host/frontend/gcastv2/libandroid/include/helpers/JavaThread.h
deleted file mode 100644
index 4694dd4..0000000
--- a/host/frontend/gcastv2/libandroid/include/helpers/JavaThread.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#pragma once
-
-#include <helpers/MyAndroidRuntime.h>
-
-#include <thread>
-
-namespace android {
-
-void javaAttachThread();
-void javaDetachThread();
-
-template<class Function, class... Args>
-std::thread createJavaThread(Function &&f, Args&&... args) {
- return std::thread([f, args...]{
- javaAttachThread();
- f(args...);
- javaDetachThread();
- });
-}
-
-} // namespace android
-
diff --git a/host/frontend/gcastv2/libandroid/include/helpers/MyAndroidRuntime.h b/host/frontend/gcastv2/libandroid/include/helpers/MyAndroidRuntime.h
deleted file mode 100644
index e1aae88..0000000
--- a/host/frontend/gcastv2/libandroid/include/helpers/MyAndroidRuntime.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#pragma once
-
-#include <jni.h>
-
-namespace android {
-
-struct MyAndroidRuntime {
- static void setJavaVM(JavaVM *vm);
- static JavaVM *getJavaVM();
-
- static JNIEnv *getJNIEnv();
-};
-
-} // namespace android
-
diff --git a/host/frontend/gcastv2/libandroid/include/helpers/MyJNIHelpers.h b/host/frontend/gcastv2/libandroid/include/helpers/MyJNIHelpers.h
deleted file mode 100644
index 0d6c9c8..0000000
--- a/host/frontend/gcastv2/libandroid/include/helpers/MyJNIHelpers.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#pragma once
-
-#include <jni.h>
-#include <sys/types.h>
-
-namespace android {
-
-void jniThrowException(
- JNIEnv *env, const char *className, const char *msg);
-
-int jniRegisterNativeMethods(
- JNIEnv *env,
- const char *className,
- const JNINativeMethod *methods,
- size_t numMethods);
-
-} // namespace android
-
diff --git a/host/frontend/gcastv2/libandroid/include/helpers/MyScopedByteArray.h b/host/frontend/gcastv2/libandroid/include/helpers/MyScopedByteArray.h
deleted file mode 100644
index 62fc607..0000000
--- a/host/frontend/gcastv2/libandroid/include/helpers/MyScopedByteArray.h
+++ /dev/null
@@ -1,26 +0,0 @@
-#pragma once
-
-#include <jni.h>
-
-namespace android {
-
-struct MyScopedByteArray {
- explicit MyScopedByteArray(JNIEnv *env, jbyteArray arrayObj);
-
- MyScopedByteArray(const MyScopedByteArray &) = delete;
- MyScopedByteArray &operator=(const MyScopedByteArray &) = delete;
-
- ~MyScopedByteArray();
-
- const jbyte *data() const;
- jsize size() const;
-
-private:
- JNIEnv *mEnv;
- jbyteArray mArrayObj;
- jbyte *mElements;
- jsize mSize;
-};
-
-} // namespace android
-
diff --git a/host/frontend/gcastv2/libandroid/include/helpers/MyScopedLocalRef.h b/host/frontend/gcastv2/libandroid/include/helpers/MyScopedLocalRef.h
deleted file mode 100644
index d683669..0000000
--- a/host/frontend/gcastv2/libandroid/include/helpers/MyScopedLocalRef.h
+++ /dev/null
@@ -1,49 +0,0 @@
-#pragma once
-
-#include <jni.h>
-
-template<class T>
-struct MyScopedLocalRef {
- explicit MyScopedLocalRef()
- : mEnv(nullptr),
- mObj(nullptr) {
- }
-
- explicit MyScopedLocalRef(JNIEnv *env, T obj)
- : mEnv(env),
- mObj(obj) {
- }
-
- MyScopedLocalRef(const MyScopedLocalRef<T> &other) = delete;
- MyScopedLocalRef &operator=(const MyScopedLocalRef<T> &other) = delete;
-
- void setTo(JNIEnv *env, T obj) {
- if (obj != mObj) {
- clear();
-
- mEnv = env;
- mObj = obj;
- }
- }
-
- void clear() {
- if (mObj) {
- mEnv->DeleteLocalRef(mObj);
- mObj = nullptr;
- }
-
- mEnv = nullptr;
- }
-
- ~MyScopedLocalRef() {
- clear();
- }
-
- T get() const {
- return mObj;
- }
-
-private:
- JNIEnv *mEnv;
- T mObj;
-};
diff --git a/host/frontend/gcastv2/libandroid/include/helpers/MyScopedUTF8String.h b/host/frontend/gcastv2/libandroid/include/helpers/MyScopedUTF8String.h
deleted file mode 100644
index 49e74e6..0000000
--- a/host/frontend/gcastv2/libandroid/include/helpers/MyScopedUTF8String.h
+++ /dev/null
@@ -1,23 +0,0 @@
-#pragma once
-
-#include <jni.h>
-
-namespace android {
-
-struct MyScopedUTF8String {
- explicit MyScopedUTF8String(JNIEnv *env, jstring stringObj);
-
- MyScopedUTF8String(const MyScopedUTF8String &) = delete;
- MyScopedUTF8String &operator=(const MyScopedUTF8String &) = delete;
-
- ~MyScopedUTF8String();
-
- const char *c_str() const;
-
-private:
- JNIEnv *mEnv;
- jstring mStringObj;
- const char *mData;
-};
-
-} // namespace android
diff --git a/host/frontend/gcastv2/libandroid/include/media/stagefright/FileSource.h b/host/frontend/gcastv2/libandroid/include/media/stagefright/FileSource.h
deleted file mode 100644
index 2f4a739..0000000
--- a/host/frontend/gcastv2/libandroid/include/media/stagefright/FileSource.h
+++ /dev/null
@@ -1,30 +0,0 @@
-#ifndef FILE_SOURCE_H_
-
-#define FILE_SOURCE_H_
-
-#include <utils/Errors.h>
-#include <utils/RefBase.h>
-
-namespace android {
-
-struct FileSource : public RefBase {
- FileSource(const char *path);
-
- status_t initCheck() const;
-
- status_t getSize(off_t *size) const;
- ssize_t readAt(off_t offset, void *data, size_t size);
-
-protected:
- virtual ~FileSource();
-
-private:
- int mFd;
- status_t mInitCheck;
-
- DISALLOW_EVIL_CONSTRUCTORS(FileSource);
-};
-
-} // namespace android
-
-#endif // FILE_SOURCE_H_
diff --git a/host/frontend/gcastv2/libandroid/include/media/stagefright/foundation/ADebug.h b/host/frontend/gcastv2/libandroid/include/media/stagefright/foundation/ADebug.h
index d415718..d5b4279 100644
--- a/host/frontend/gcastv2/libandroid/include/media/stagefright/foundation/ADebug.h
+++ b/host/frontend/gcastv2/libandroid/include/media/stagefright/foundation/ADebug.h
@@ -2,124 +2,7 @@
#define A_DEBUG_H_
-#ifdef TARGET_ANDROID
#include <android-base/logging.h>
-#else
-
-#include "ABase.h"
-
-#include <stdarg.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <string>
-#include <string_view>
-
-enum LogType {
- VERBOSE,
- INFO,
- WARNING,
- ERROR,
- FATAL,
-};
-
-namespace android {
-
-struct Logger {
- Logger(LogType type);
- virtual ~Logger();
-
- Logger &operator<<(std::string_view x) {
- mMessage.append(x);
- return *this;
- }
-
- Logger &operator<<(const std::string &x) {
- mMessage.append(x);
- return *this;
- }
-
- Logger &operator<<(const char *x) {
- mMessage.append(x);
- return *this;
- }
-
- Logger &operator<<(char *x) {
- mMessage.append(x);
- return *this;
- }
-
- template<class T> Logger &operator<<(const T &x) {
- mMessage.append(std::to_string(x));
- return *this;
- }
-
-private:
- std::string mMessage;
- LogType mLogType;
-
- DISALLOW_EVIL_CONSTRUCTORS(Logger);
-};
-
-const char *LeafName(const char *s);
-
-#undef LOG
-#define LOG(type) \
- android::Logger(type) \
- << android::LeafName(__FILE__) << ":" << __LINE__ << " "
-
-#define CHECK(condition) \
- do { \
- if (!(condition)) { \
- LOG(FATAL) << "CHECK(" #condition ") failed."; \
- } \
- } while (false)
-
-using std::to_string;
-
-inline std::string to_string(std::string_view s) {
- return std::string(s);
-}
-
-#define MAKE_COMPARATOR(suffix,op) \
- template<class A, class B> \
- std::string Compare_##suffix(const A &a, const B &b) { \
- std::string res; \
- if (!(a op b)) { \
- res.append(to_string(a)); \
- res.append(" vs. "); \
- res.append(to_string(b)); \
- } \
- return res; \
- }
-
-MAKE_COMPARATOR(EQ,==)
-MAKE_COMPARATOR(NE,!=)
-MAKE_COMPARATOR(LE,<=)
-MAKE_COMPARATOR(GE,>=)
-MAKE_COMPARATOR(LT,<)
-MAKE_COMPARATOR(GT,>)
-
-#define CHECK_OP(x,y,suffix,op) \
- do { \
- std::string ___res = android::Compare_##suffix(x, y); \
- if (!___res.empty()) { \
- LOG(FATAL) << "CHECK_" #suffix "(" #x "," #y ") failed: " \
- << ___res; \
- } \
- } while (false)
-
-#define CHECK_EQ(x,y) CHECK_OP(x,y,EQ,==)
-#define CHECK_NE(x,y) CHECK_OP(x,y,NE,!=)
-#define CHECK_LE(x,y) CHECK_OP(x,y,LE,<=)
-#define CHECK_LT(x,y) CHECK_OP(x,y,LT,<)
-#define CHECK_GE(x,y) CHECK_OP(x,y,GE,>=)
-#define CHECK_GT(x,y) CHECK_OP(x,y,GT,>)
-
-} // namespace android
-
-#endif // defined(TARGET_ANDROID)
-
namespace android {
#define TRESPASS() LOG(FATAL) << "Should not be here."
diff --git a/host/frontend/gcastv2/libandroid/include/media/stagefright/foundation/ANetworkSession.h b/host/frontend/gcastv2/libandroid/include/media/stagefright/foundation/ANetworkSession.h
deleted file mode 100644
index 3fa26ba..0000000
--- a/host/frontend/gcastv2/libandroid/include/media/stagefright/foundation/ANetworkSession.h
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Copyright 2012, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef A_NETWORK_SESSION_H_
-
-#define A_NETWORK_SESSION_H_
-
-#include <media/stagefright/foundation/ABase.h>
-#include <utils/RefBase.h>
-#include <utils/threads.h>
-
-#include <netinet/in.h>
-
-#include <map>
-
-namespace android {
-
-struct AMessage;
-
-// Helper class to manage a number of live sockets (datagram and stream-based)
-// on a single thread. Clients are notified about activity through AMessages.
-struct ANetworkSession : public RefBase {
- ANetworkSession();
-
- status_t start();
- status_t stop();
-
- status_t createRTSPClient(
- const char *host, unsigned port, const sp<AMessage> ¬ify,
- int32_t *sessionID);
-
- status_t createRTSPServer(
- const struct in_addr &addr, unsigned port,
- const sp<AMessage> ¬ify, int32_t *sessionID);
-
- status_t createUDPSession(
- unsigned localPort, const sp<AMessage> ¬ify, int32_t *sessionID);
-
- status_t createUDPSession(
- unsigned localPort,
- const char *remoteHost,
- unsigned remotePort,
- const sp<AMessage> ¬ify,
- int32_t *sessionID);
-
- status_t connectUDPSession(
- int32_t sessionID, const char *remoteHost, unsigned remotePort);
-
- // passive
- status_t createTCPDatagramSession(
- const struct in_addr &addr, unsigned port,
- const sp<AMessage> ¬ify, int32_t *sessionID);
-
- // active
- status_t createTCPDatagramSession(
- unsigned localPort,
- const char *remoteHost,
- unsigned remotePort,
- const sp<AMessage> ¬ify,
- int32_t *sessionID);
-
- status_t destroySession(int32_t sessionID);
-
- status_t sendRequest(
- int32_t sessionID, const void *data, ssize_t size = -1,
- bool timeValid = false, int64_t timeUs = -1ll);
-
- status_t switchToWebSocketMode(int32_t sessionID);
-
- enum NotificationReason {
- kWhatError,
- kWhatConnected,
- kWhatClientConnected,
- kWhatData,
- kWhatDatagram,
- kWhatBinaryData,
- kWhatWebSocketMessage,
- kWhatNetworkStall,
- };
-
-protected:
- virtual ~ANetworkSession();
-
-private:
- struct NetworkThread;
- struct Session;
-
- Mutex mLock;
- sp<Thread> mThread;
-
- int32_t mNextSessionID;
-
- int mPipeFd[2];
-
- std::map<int32_t, sp<Session> > mSessions;
-
- enum Mode {
- kModeCreateUDPSession,
- kModeCreateTCPDatagramSessionPassive,
- kModeCreateTCPDatagramSessionActive,
- kModeCreateRTSPServer,
- kModeCreateRTSPClient,
- };
- status_t createClientOrServer(
- Mode mode,
- const struct in_addr *addr,
- unsigned port,
- const char *remoteHost,
- unsigned remotePort,
- const sp<AMessage> ¬ify,
- int32_t *sessionID);
-
- void threadLoop();
- void interrupt();
-
- static status_t MakeSocketNonBlocking(int s);
-
- DISALLOW_EVIL_CONSTRUCTORS(ANetworkSession);
-};
-
-} // namespace android
-
-#endif // A_NETWORK_SESSION_H_
diff --git a/host/frontend/gcastv2/libandroid/include/media/stagefright/foundation/ReflectorHandler.h b/host/frontend/gcastv2/libandroid/include/media/stagefright/foundation/ReflectorHandler.h
deleted file mode 100644
index cc1cadc..0000000
--- a/host/frontend/gcastv2/libandroid/include/media/stagefright/foundation/ReflectorHandler.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#pragma once
-
-#include <media/stagefright/foundation/AHandler.h>
-
-namespace android {
-
-template<class T>
-struct ReflectorHandler : public AHandler {
- explicit ReflectorHandler(T *target)
- : mTarget(target) {
- }
-
- void onMessageReceived(const sp<AMessage> &msg) {
- mTarget->onMessageReceived(msg);
- }
-
-private:
- T *mTarget;
-};
-
-} // namespace android
-
diff --git a/host/frontend/gcastv2/libandroid/include/media/stagefright/foundation/base64.h b/host/frontend/gcastv2/libandroid/include/media/stagefright/foundation/base64.h
deleted file mode 100644
index e4f627b..0000000
--- a/host/frontend/gcastv2/libandroid/include/media/stagefright/foundation/base64.h
+++ /dev/null
@@ -1,19 +0,0 @@
-#ifndef BASE_64_H_
-
-#define BASE_64_H_
-
-#include <utils/RefBase.h>
-
-#include <string>
-#include <string_view>
-
-namespace android {
-
-struct ABuffer;
-
-sp<ABuffer> decodeBase64(const std::string_view &s);
-void encodeBase64(const void *data, size_t size, std::string *out);
-
-} // namespace android
-
-#endif // BASE_64_H_
diff --git a/host/frontend/gcastv2/libandroid/include/utils/KeyStore.h b/host/frontend/gcastv2/libandroid/include/utils/KeyStore.h
deleted file mode 100644
index 1cbfd55..0000000
--- a/host/frontend/gcastv2/libandroid/include/utils/KeyStore.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#pragma once
-
-#include <cstdint>
-#include <string>
-#include <vector>
-
-void setCertificateOrKey(
- const std::string &name, const void *_data, size_t size);
-
-bool getCertificateOrKey(
- const std::string &name, std::vector<uint8_t> *data);
-
diff --git a/host/frontend/gcastv2/libandroid/include/utils/threads.h b/host/frontend/gcastv2/libandroid/include/utils/threads.h
index f6e0cb1..8d3ce05 100644
--- a/host/frontend/gcastv2/libandroid/include/utils/threads.h
+++ b/host/frontend/gcastv2/libandroid/include/utils/threads.h
@@ -10,21 +10,13 @@
#include <utils/Errors.h>
#include <utils/RefBase.h>
-#ifdef TARGET_ANDROID_DEVICE
-#include <helpers/JavaThread.h>
-#include <memory>
-#include <thread>
-#else
#include <pthread.h>
-#endif
namespace android {
struct Thread : public RefBase {
Thread()
-#ifndef TARGET_ANDROID_DEVICE
: mThread(0)
-#endif
{
}
@@ -36,12 +28,6 @@
mName = name;
mExitRequested = false;
-#ifdef TARGET_ANDROID_DEVICE
- mThread = std::make_unique<std::thread>(
- createJavaThread([this] {
- (void)ThreadWrapper(this);
- }));
-#else
int res = pthread_create(&mThread, NULL, &Thread::ThreadWrapper, this);
if (res != 0) {
@@ -49,7 +35,6 @@
return -errno;
}
-#endif
return OK;
}
@@ -58,17 +43,9 @@
void requestExitAndWait() {
requestExit();
-
-#ifdef TARGET_ANDROID_DEVICE
- if (mThread) {
- mThread->join();
- mThread.reset();
- }
-#else
void *dummy;
pthread_join(mThread, &dummy);
mThread = 0;
-#endif
}
protected:
@@ -83,11 +60,7 @@
}
private:
-#ifdef TARGET_ANDROID_DEVICE
- std::unique_ptr<std::thread> mThread;
-#else
pthread_t mThread;
-#endif
volatile bool mExitRequested;
std::string mName;
diff --git a/host/frontend/gcastv2/libsource/AACPlayer.cpp b/host/frontend/gcastv2/libsource/AACPlayer.cpp
deleted file mode 100644
index eb1d761..0000000
--- a/host/frontend/gcastv2/libsource/AACPlayer.cpp
+++ /dev/null
@@ -1,496 +0,0 @@
-//#define LOG_NDEBUG 0
-#define LOG_TAG "AACPlayer"
-#include <utils/Log.h>
-
-#include <source/AACPlayer.h>
-
-#include <algorithm>
-
-namespace android {
-
-static void check(OSStatus err, const char *file, int line) {
- if (err == noErr) {
- return;
- }
-
- ALOGE("check FAILED w/ error %d at %s:%d", err, file, line);
- TRESPASS();
-}
-
-#define CHECK_OSSTATUS(err) do { check(err, __FILE__, __LINE__); } while (0)
-
-static constexpr int32_t kSampleRate[] = {
- 96000, 88200, 64000, 48000, 44100, 32000,
- 24000, 22050, 16000, 12000, 11025, 8000
-};
-
-AACPlayer::AACPlayer()
- : mConverter(nullptr),
-#if USE_AUDIO_UNIT
- mGraph(nullptr),
-#else
- mQueue(nullptr),
-#endif
- mSampleRateHz(-1),
- mNumFramesSubmitted(0) {
-}
-
-AACPlayer::~AACPlayer() {
-#if USE_AUDIO_UNIT
- if (mGraph) {
- DisposeAUGraph(mGraph);
- mGraph = nullptr;
- }
-#else
- if (mQueue) {
- AudioQueueStop(mQueue, true /* immediate */);
- AudioQueueDispose(mQueue, true /* immediate */);
- mQueue = nullptr;
- }
-#endif
-
- if (mConverter) {
- AudioConverterDispose(mConverter);
- mConverter = nullptr;
- }
-}
-
-struct FeedCookie {
- const void *data;
- size_t size;
-};
-
-static OSStatus FeedInputData(
- AudioConverterRef /* converter */,
- UInt32 *numDataPackets,
- AudioBufferList *data,
- AudioStreamPacketDescription **dataPacketDescription,
- void *_cookie) {
- FeedCookie *cookie = static_cast<FeedCookie *>(_cookie);
-
- assert(*numDataPackets == 1);
- assert(data->mNumberBuffers == 1);
-
- assert(cookie->size > 0);
- data->mBuffers[0].mNumberChannels = 0;
- data->mBuffers[0].mDataByteSize = static_cast<UInt32>(cookie->size);
- data->mBuffers[0].mData = const_cast<void *>(cookie->data);
-
- if (dataPacketDescription) {
- static AudioStreamPacketDescription desc;
- desc.mDataByteSize = static_cast<UInt32>(cookie->size);
- desc.mStartOffset = 0;
- desc.mVariableFramesInPacket = 0;
-
- *dataPacketDescription = &desc;
- }
-
- cookie->size = 0;
-
- return noErr;
-}
-
-status_t AACPlayer::feedADTSFrame(const void *_frame, size_t size) {
- const uint8_t *frame = static_cast<const uint8_t *>(_frame);
-
- static constexpr size_t kADTSHeaderSize = 7;
-
- if (size < kADTSHeaderSize) {
- return -EINVAL;
- }
-
- if (frame[0] != 0xff || (frame[1] >> 4) != 0xf) {
- return -EINVAL;
- }
-
- const size_t frameSize =
- (static_cast<size_t>(frame[3]) & 0x3f) << 11
- | static_cast<size_t>(frame[4]) << 3
- | frame[5] >> 5;
-
- if (size != frameSize) {
- return -EINVAL;
- }
-
- if (mConverter == nullptr) {
- // size_t profile = (frame[2] >> 6) + 1;
- int32_t sampleRateIndex = (frame[2] >> 2) & 15;
- int32_t channelCount = ((frame[2] & 3) << 2) | (frame[3] >> 6);
-
- int32_t sampleRate = kSampleRate[sampleRateIndex];
-
- status_t err = init(sampleRateIndex, channelCount);
- if (err != OK) {
- return err;
- }
-
- mSampleRateHz = sampleRate;
- }
-
-#if USE_AUDIO_UNIT
- struct OutputBuffer {
- void *mAudioData;
- UInt32 mAudioDataByteSize;
- };
-
- const size_t outBufferSize = mBufferQueue->bufferSize();
- std::unique_ptr<OutputBuffer> outBuffer(new OutputBuffer);
- outBuffer->mAudioData = mBufferQueue->acquire();
- outBuffer->mAudioDataByteSize = 0;
-#else
- const size_t outBufferSize = mBufferManager->bufferSize();
- AudioQueueBufferRef outBuffer = mBufferManager->acquire();
-#endif
-
- UInt32 outputDataPacketSize = mInFormat.mFramesPerPacket;
- AudioBufferList outputData;
- outputData.mNumberBuffers = 1;
- outputData.mBuffers[0].mData = outBuffer->mAudioData;
- outputData.mBuffers[0].mDataByteSize = static_cast<UInt32>(outBufferSize);
- outputData.mBuffers[0].mNumberChannels = mInFormat.mChannelsPerFrame;
-
- FeedCookie cookie;
- cookie.data = &frame[kADTSHeaderSize];
- cookie.size = frameSize - kADTSHeaderSize;
-
- OSStatus err = AudioConverterFillComplexBuffer(
- mConverter,
- FeedInputData,
- &cookie,
- &outputDataPacketSize,
- &outputData,
- nullptr);
-
- CHECK_OSSTATUS(err);
-
- assert(outputDataPacketSize == mInFormat.mFramesPerPacket);
- assert(outputData.mNumberBuffers == 1);
-
- outBuffer->mAudioDataByteSize = outputData.mBuffers[0].mDataByteSize;
-
-#if USE_AUDIO_UNIT
- mBufferQueue->queue(outBuffer->mAudioData);
-#else
- err = AudioQueueEnqueueBuffer(
- mQueue,
- outBuffer,
- 0 /* numPacketDescs */,
- nullptr /* packetDescs */);
-
- CHECK_OSSTATUS(err);
-#endif
-
- mNumFramesSubmitted += 1024;
-
- return OK;
-}
-
-int32_t AACPlayer::sampleRateHz() const {
- return mSampleRateHz;
-}
-
-static void writeInt16(uint8_t *&ptr, uint16_t x) {
- *ptr++ = x >> 8;
- *ptr++ = x & 0xff;
-}
-
-static void writeInt32(uint8_t *&ptr, uint32_t x) {
- writeInt16(ptr, x >> 16);
- writeInt16(ptr, x & 0xffff);
-}
-
-static void writeInt24(uint8_t *&ptr, uint32_t x) {
- *ptr++ = (x >> 16) & 0xff;
- writeInt16(ptr, x & 0xffff);
-}
-
-static void writeDescriptor(uint8_t *&ptr, uint8_t tag, size_t size) {
- *ptr++ = tag;
- for (size_t i = 3; i > 0; --i) {
- *ptr++ = (size >> (7 * i)) | 0x80;
- }
- *ptr++ = size & 0x7f;
-}
-
-#if !USE_AUDIO_UNIT
-static void PropertyListenerCallback(
- void * /* cookie */,
- AudioQueueRef queue,
- AudioQueuePropertyID /* propertyID */) {
- UInt32 isRunning;
- UInt32 size = sizeof(isRunning);
-
- OSStatus err = AudioQueueGetProperty(
- queue, kAudioQueueProperty_IsRunning, &isRunning, &size);
-
- CHECK_OSSTATUS(err);
- CHECK_EQ(size, sizeof(isRunning));
-
- ALOGI("AudioQueue is now %s", isRunning ? "running" : "stopped");
-}
-#else
-// static
-OSStatus AACPlayer::FeedInput(
- void *cookie,
- AudioUnitRenderActionFlags * /* flags */,
- const AudioTimeStamp * /* timeStamp */,
- UInt32 /* bus */,
- UInt32 numFrames,
- AudioBufferList *data) {
- AACPlayer *me = static_cast<AACPlayer *>(cookie);
-
- UInt32 curFrame = 0;
- void *outPtr = data->mBuffers[0].mData;
-
- const size_t bytesPerFrame = me->mOutFormat.mBytesPerFrame;
-
- while (curFrame < numFrames) {
- size_t inSize;
- const void *inData = me->mBufferQueue->dequeueBegin(&inSize);
-
- if (inData == nullptr) {
- // underrun
- memset(outPtr, 0, (numFrames - curFrame) * bytesPerFrame);
- break;
- }
-
- const size_t inSizeFrames = inSize / bytesPerFrame;
-
- const size_t copyFrames =
- std::min(inSizeFrames, static_cast<size_t>(numFrames - curFrame));
-
- const size_t copyBytes = copyFrames * bytesPerFrame;
-
- memcpy(outPtr, inData, copyBytes);
- outPtr = (uint8_t *)outPtr + copyBytes;
-
- me->mBufferQueue->dequeueEnd(inSize - copyBytes);
-
- curFrame += copyFrames;
- }
-
- data->mBuffers[0].mDataByteSize = numFrames * static_cast<UInt32>(bytesPerFrame);
-
- return noErr;
-}
-#endif
-
-status_t AACPlayer::init(int32_t sampleRateIndex, size_t channelCount) {
- const int32_t sampleRate = kSampleRate[sampleRateIndex];
-
- memset(&mOutFormat, 0, sizeof(mOutFormat));
-
- mOutFormat.mSampleRate = static_cast<double>(sampleRate);
- mOutFormat.mBitsPerChannel = 8 * sizeof(float);
- mOutFormat.mChannelsPerFrame = static_cast<UInt32>(channelCount);
-
- mOutFormat.mFormatID = kAudioFormatLinearPCM;
- mOutFormat.mFormatFlags = kAudioFormatFlagIsFloat | kAudioFormatFlagIsPacked;
-
- mOutFormat.mFramesPerPacket = 1;
-
- mOutFormat.mBytesPerFrame =
- (mOutFormat.mBitsPerChannel / 8) * mOutFormat.mChannelsPerFrame;
-
- mOutFormat.mBytesPerPacket =
- mOutFormat.mBytesPerFrame * mOutFormat.mFramesPerPacket;
-
- memset(&mInFormat, 0, sizeof(mInFormat));
-
- mInFormat.mSampleRate = static_cast<double>(sampleRate);
- mInFormat.mBitsPerChannel = 0; // compressed
- mInFormat.mChannelsPerFrame = static_cast<UInt32>(channelCount);
-
- mInFormat.mFormatID = kAudioFormatMPEG4AAC;
- mInFormat.mFormatFlags = kMPEG4Object_AAC_LC;
-
- mInFormat.mFramesPerPacket = 1024;
-
- mInFormat.mBytesPerFrame = 0; // variable
- mInFormat.mBytesPerPacket = 0; // variable
-
- OSStatus err = AudioConverterNew(&mInFormat, &mOutFormat, &mConverter);
- CHECK_OSSTATUS(err);
- assert(mConverter != nullptr);
-
- // static constexpr uint8_t kAACCodecSpecificData[] = {0x11,0x90};
- // static constexpr uint8_t kAACCodecSpecificData[] = {0x12,0x10};
-
- // 5 bits: object type
- // 4 bits: frequency index
- // if (frequency index == 15) { 24 bits frequency }
- // 4 bits: channel config
- // 1 bit: frame length flag
- // 1 bit: dependsOnCoreCoder
- // 1 bit: extensionFlag
-
- // 0x11 0x90 => 00010 0011 0010 0 0 0 (AAC LC, 48kHz, 2 channels)
- // 0x12 0x10 => 00010 0100 0010 0 0 0 (AAC LC, 44.1kHz, 2 channels)
-
- uint8_t kAACCodecSpecificData[2];
-
- kAACCodecSpecificData[0] =
- (2 << 3) /* AAC LC */ | (sampleRateIndex >> 1);
-
- kAACCodecSpecificData[1] =
- ((sampleRateIndex & 1) << 7) | (channelCount << 3);
-
- static constexpr size_t kAACCodecSpecificDataSize =
- sizeof(kAACCodecSpecificData);
-
- uint8_t magic[128];
- uint8_t *ptr = magic;
- writeDescriptor(ptr, 0x03, 3 + 5 + 13 + 5 + kAACCodecSpecificDataSize);
- writeInt16(ptr, 0x00);
- *ptr++ = 0x00;
-
- // DecoderConfig descriptor
- writeDescriptor(ptr, 0x04, 13 + 5 + kAACCodecSpecificDataSize);
-
- // Object type indication
- *ptr++ = 0x40;
-
- // Flags (= Audiostream)
- *ptr++ = 0x15;
-
- writeInt24(ptr, 0); // BufferSize DB
- writeInt32(ptr, 0); // max bitrate
- writeInt32(ptr, 0); // avg bitrate
-
- writeDescriptor(ptr, 0x05, kAACCodecSpecificDataSize);
- memcpy(ptr, kAACCodecSpecificData, kAACCodecSpecificDataSize);
- ptr += kAACCodecSpecificDataSize;
-
- size_t magicSize = ptr - magic;
-
- err = AudioConverterSetProperty(
- mConverter,
- kAudioConverterDecompressionMagicCookie,
- static_cast<UInt32>(magicSize),
- magic);
-
- CHECK_OSSTATUS(err);
-
-#if USE_AUDIO_UNIT
- err = NewAUGraph(&mGraph);
- CHECK_OSSTATUS(err);
-
- AudioComponentDescription desc;
- desc.componentFlags = 0;
- desc.componentFlagsMask = 0;
- desc.componentManufacturer = kAudioUnitManufacturer_Apple;
- desc.componentType = kAudioUnitType_Output;
-
-#ifdef TARGET_IOS
- desc.componentSubType = kAudioUnitSubType_RemoteIO;
-#else
- desc.componentSubType = kAudioUnitSubType_DefaultOutput;
-#endif
-
- err = AUGraphAddNode(mGraph, &desc, &mOutputNode);
- CHECK_OSSTATUS(err);
-
- struct AURenderCallbackStruct cb;
- cb.inputProc = FeedInput;
- cb.inputProcRefCon = this;
-
- err = AUGraphSetNodeInputCallback(
- mGraph, mOutputNode, 0 /* inputNumber */, &cb);
-
- CHECK_OSSTATUS(err);
-
- err = AUGraphOpen(mGraph);
- CHECK_OSSTATUS(err);
-
- AudioUnit outputUnit;
- err = AUGraphNodeInfo(mGraph, mOutputNode, &desc, &outputUnit);
- CHECK_OSSTATUS(err);
-
- err = AudioUnitSetProperty(
- outputUnit,
- kAudioUnitProperty_StreamFormat,
- kAudioUnitScope_Input,
- 0 /* busNumber */,
- &mOutFormat,
- sizeof(mOutFormat));
-
- CHECK_OSSTATUS(err);
-
- err = AUGraphInitialize(mGraph);
- CHECK_OSSTATUS(err);
-
- mBufferQueue.reset(
- new BufferQueue(
- 8 /* count */,
- mInFormat.mFramesPerPacket
- * mInFormat.mChannelsPerFrame * sizeof(float)));
-
- err = AUGraphStart(mGraph);
- CHECK_OSSTATUS(err);
-#else
- err = AudioQueueNewOutput(
- &mOutFormat,
- PlayCallback,
- this,
- nullptr /* callbackRunLoop */,
- kCFRunLoopCommonModes,
- 0 /* flags */,
- &mQueue);
-
- CHECK_OSSTATUS(err);
-
- UInt32 enablePitch = 1;
- err = AudioQueueSetProperty(
- mQueue,
- kAudioQueueProperty_EnableTimePitch,
- &enablePitch,
- sizeof(enablePitch));
-
- CHECK_OSSTATUS(err);
-
-#if 0
- UInt32 pitchAlgorithm = kAudioQueueTimePitchAlgorithm_Spectral;
- err = AudioQueueSetProperty(
- mQueue,
- kAudioQueueProperty_TimePitchAlgorithm,
- &pitchAlgorithm,
- sizeof(pitchAlgorithm));
-
- CHECK_OSSTATUS(err);
-#endif
-
- err = AudioQueueSetParameter(mQueue, kAudioQueueParam_PlayRate, 1.0 /* 0.99 */);
- CHECK_OSSTATUS(err);
-
- err = AudioQueueAddPropertyListener(
- mQueue,
- kAudioQueueProperty_IsRunning,
- PropertyListenerCallback,
- this);
-
- CHECK_OSSTATUS(err);
-
- mBufferManager.reset(
- new android::AudioQueueBufferManager(
- mQueue,
- 32 /* count */,
- mInFormat.mFramesPerPacket * channelCount * sizeof(float)));
-
- err = AudioQueueStart(mQueue, nullptr /* startTime */);
- CHECK_OSSTATUS(err);
-#endif
-
- return OK;
-}
-
-#if !USE_AUDIO_UNIT
-// static
-void AACPlayer::PlayCallback(
- void *cookie, AudioQueueRef /* queue */, AudioQueueBufferRef buffer) {
- AACPlayer *me = static_cast<AACPlayer *>(cookie);
- me->mBufferManager->release(buffer);
-}
-#endif
-
-} // namespace android
-
diff --git a/host/frontend/gcastv2/libsource/AACPlayer.h b/host/frontend/gcastv2/libsource/AACPlayer.h
deleted file mode 100644
index 59a52b8..0000000
--- a/host/frontend/gcastv2/libsource/AACPlayer.h
+++ /dev/null
@@ -1,61 +0,0 @@
-#pragma once
-
-#include <source/AudioQueueBufferManager.h>
-#include <source/BufferQueue.h>
-
-#include <utils/Errors.h>
-
-#include <sys/types.h>
-
-#include <AudioToolbox/AudioToolbox.h>
-
-#include <memory>
-
-namespace android {
-
-#define USE_AUDIO_UNIT 1
-
-struct AACPlayer {
- explicit AACPlayer();
- ~AACPlayer();
-
- AACPlayer(const AACPlayer &) = delete;
- AACPlayer &operator=(const AACPlayer &) = delete;
-
- status_t feedADTSFrame(const void *frame, size_t size);
-
- int32_t sampleRateHz() const;
-
-private:
- AudioStreamBasicDescription mInFormat, mOutFormat;
- AudioConverterRef mConverter;
-
-#if USE_AUDIO_UNIT
- AUGraph mGraph;
- AUNode mOutputNode;
- std::unique_ptr<BufferQueue> mBufferQueue;
-#else
- AudioQueueRef mQueue;
- std::unique_ptr<AudioQueueBufferManager> mBufferManager;
-#endif
-
- int32_t mSampleRateHz;
- int64_t mNumFramesSubmitted;
-
- status_t init(int32_t sampleRate, size_t channelCount);
-
-#if !USE_AUDIO_UNIT
- static void PlayCallback(
- void *_cookie, AudioQueueRef queue, AudioQueueBufferRef buffer);
-#else
- static OSStatus FeedInput(
- void *cookie,
- AudioUnitRenderActionFlags *flags,
- const AudioTimeStamp *timeStamp,
- UInt32 bus,
- UInt32 numFrames,
- AudioBufferList *data);
-#endif
-};
-
-} // namespace android
diff --git a/host/frontend/gcastv2/libsource/Android.bp b/host/frontend/gcastv2/libsource/Android.bp
index 193615e..571c0f4 100644
--- a/host/frontend/gcastv2/libsource/Android.bp
+++ b/host/frontend/gcastv2/libsource/Android.bp
@@ -17,19 +17,15 @@
srcs: [
"AudioSource.cpp",
"TouchSink.cpp",
- "DisplayListsSource.cpp",
"FrameBufferSource.cpp",
"HostToGuestComms.cpp",
"StreamingSource.cpp",
- "TouchSource.cpp",
],
header_libs: [
"cuttlefish_glog",
],
shared_libs: [
"libbase",
- "libFraunhoferAAC",
-// "libx264",
"libyuv",
"libopus",
"libvpx",
@@ -40,9 +36,6 @@
"libgflags",
"libhttps",
],
- cflags: [
- "-DTARGET_ANDROID",
- ],
local_include_dirs: ["include"],
export_include_dirs: ["include"],
defaults: ["cuttlefish_host_only"],
diff --git a/host/frontend/gcastv2/libsource/AudioQueueBufferManager.cpp b/host/frontend/gcastv2/libsource/AudioQueueBufferManager.cpp
deleted file mode 100644
index b1954c3..0000000
--- a/host/frontend/gcastv2/libsource/AudioQueueBufferManager.cpp
+++ /dev/null
@@ -1,85 +0,0 @@
-#include <source/AudioQueueBufferManager.h>
-
-#include <media/stagefright/foundation/ALooper.h>
-
-namespace android {
-
-AudioQueueBufferManager::AudioQueueBufferManager(
- AudioQueueRef queue, size_t count, size_t size)
- : mInitCheck(NO_INIT),
- mQueue(queue),
- mBufferSize(size) {
- for (size_t i = 0; i < count; ++i) {
- AudioQueueBufferRef buffer;
- OSStatus err = AudioQueueAllocateBuffer(mQueue, static_cast<UInt32>(size), &buffer);
-
- if (err != noErr) {
- mInitCheck = -ENOMEM;
- return;
- }
-
- mBuffers.push_back(buffer);
- }
-
- mInitCheck = OK;
-}
-
-AudioQueueBufferManager::~AudioQueueBufferManager() {
- for (auto buffer : mBuffers) {
- AudioQueueFreeBuffer(mQueue, buffer);
- }
-}
-
-status_t AudioQueueBufferManager::initCheck() const {
- return mInitCheck;
-}
-
-size_t AudioQueueBufferManager::bufferSize() const {
- return mBufferSize;
-}
-
-AudioQueueBufferRef AudioQueueBufferManager::acquire(int64_t timeoutUs) {
- int64_t waitUntilUs =
- (timeoutUs < 0ll) ? -1ll : ALooper::GetNowUs() + timeoutUs;
-
- std::unique_lock<std::mutex> autoLock(mLock);
- while (mBuffers.empty()) {
- if (waitUntilUs < 0ll) {
- mCondition.wait(autoLock);
- } else {
- int64_t nowUs = ALooper::GetNowUs();
-
- if (nowUs >= waitUntilUs) {
- break;
- }
-
- auto result = mCondition.wait_for(
- autoLock, std::chrono::microseconds(waitUntilUs - nowUs));
-
- if (result == std::cv_status::timeout) {
- break;
- }
- }
- }
-
- if (mBuffers.empty()) {
- return nullptr;
- }
-
- auto result = mBuffers.front();
- mBuffers.pop_front();
-
- return result;
-}
-
-void AudioQueueBufferManager::release(AudioQueueBufferRef buffer) {
- std::lock_guard<std::mutex> autoLock(mLock);
- bool wasEmpty = mBuffers.empty();
- mBuffers.push_back(buffer);
- if (wasEmpty) {
- mCondition.notify_all();
- }
-}
-
-} // namespace android
-
diff --git a/host/frontend/gcastv2/libsource/AudioSink.cpp b/host/frontend/gcastv2/libsource/AudioSink.cpp
deleted file mode 100644
index f8fad19..0000000
--- a/host/frontend/gcastv2/libsource/AudioSink.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-#include <source/AudioSink.h>
-
-#include <media/stagefright/foundation/ABuffer.h>
-#include <media/stagefright/foundation/AMessage.h>
-
-namespace android {
-
-AudioSink::AudioSink()
- : mAACPlayer(new AACPlayer) {
-#if LOG_AUDIO
- mFile = fopen("/tmp/audio.aac", "w");
- CHECK(mFile);
-#endif
-}
-
-void AudioSink::onMessageReceived(const sp<AMessage> &msg) {
- switch (msg->what()) {
- case kWhatAccessUnit:
- {
- sp<ABuffer> accessUnit;
- CHECK(msg->findBuffer("accessUnit", &accessUnit));
- mAACPlayer->feedADTSFrame(accessUnit->data(), accessUnit->size());
-
-#if LOG_AUDIO
- fwrite(accessUnit->data(), 1, accessUnit->size(), mFile);
- fflush(mFile);
-#endif
- break;
- }
-
- default:
- TRESPASS();
- }
-}
-
-} // namespace android
-
diff --git a/host/frontend/gcastv2/libsource/AudioSource.cpp b/host/frontend/gcastv2/libsource/AudioSource.cpp
index 92b7fc4..afc9ccd 100644
--- a/host/frontend/gcastv2/libsource/AudioSource.cpp
+++ b/host/frontend/gcastv2/libsource/AudioSource.cpp
@@ -11,8 +11,6 @@
#include "host/libs/config/cuttlefish_config.h"
-#include <aacenc_lib.h>
-
#include <opus.h>
#include <gflags/gflags.h>
@@ -128,329 +126,6 @@
mOnFrameFn = onFrameFn;
}
-struct AudioSource::AACEncoder : public AudioSource::Encoder {
- explicit AACEncoder(bool useADTSFraming);
- ~AACEncoder() override;
-
- status_t initCheck() const override;
-
- AACEncoder(const AACEncoder &) = delete;
- AACEncoder &operator=(const AACEncoder &) = delete;
-
- void encode(const void *data, size_t size) override;
- void reset() override;
-
-private:
- static constexpr unsigned kAACProfile = AOT_AAC_LC;
-
- status_t mInitCheck;
-
- bool mUseADTSFraming;
-
- gce_audio_message mPrevHeader;
- bool mPrevHeaderValid;
-
- HANDLE_AACENCODER mImpl;
-
- sp<ABuffer> mConfig;
- sp<ABuffer> mInputFrame;
-
- size_t mADTSSampleRateIndex;
- size_t mChannelCount;
-
- FILE *mLogFile;
-
- void fillADTSHeader(const sp<ABuffer> &outBuffer) const;
- static bool GetSampleRateIndex(int32_t sampleRate, size_t *tableIndex);
-};
-
-AudioSource::AACEncoder::AACEncoder(bool useADTSFraming)
- : mInitCheck(NO_INIT),
- mUseADTSFraming(useADTSFraming),
- mPrevHeaderValid(false),
- mImpl(nullptr),
- mADTSSampleRateIndex(0),
- mChannelCount(0),
- mLogFile(nullptr) {
- reset();
-
- if (mImpl != nullptr) {
- mInitCheck = OK;
- }
-}
-
-AudioSource::AACEncoder::~AACEncoder() {
- if (mLogFile != nullptr) {
- fclose(mLogFile);
- mLogFile = nullptr;
- }
-
- if (mImpl != nullptr) {
- aacEncClose(&mImpl);
- mImpl = nullptr;
- }
-}
-
-status_t AudioSource::AACEncoder::initCheck() const {
- return mInitCheck;
-}
-
-void AudioSource::AACEncoder::reset() {
- if (mLogFile != nullptr) {
- fclose(mLogFile);
- mLogFile = nullptr;
- }
-
-#if LOG_AUDIO
- mLogFile = fopen("/tmp/log_remote.aac", "wb");
- CHECK(mLogFile != nullptr);
-#endif
-
- if (mImpl != nullptr) {
- aacEncClose(&mImpl);
- mImpl = nullptr;
- }
-
- if (aacEncOpen(&mImpl, 0, 0) != AACENC_OK) {
- mImpl = nullptr;
- return;
- }
-
- mPrevHeaderValid = false;
-}
-
-void AudioSource::AACEncoder::encode(const void *_data, size_t size) {
- auto data = static_cast<const uint8_t *>(_data);
-
- CHECK_GE(size, sizeof(gce_audio_message));
-
- gce_audio_message hdr;
- std::memcpy(&hdr, data, sizeof(gce_audio_message));
-
- if (hdr.message_type != gce_audio_message::DATA_SAMPLES) {
- return;
- }
-
- int64_t timeUs =
- static_cast<int64_t>(hdr.time_presented.tv_sec) * 1000000ll
- + (hdr.time_presented.tv_nsec + 500) / 1000;
-
- if (!mPrevHeaderValid
- || mPrevHeader.frame_size != hdr.frame_size
- || mPrevHeader.frame_rate != hdr.frame_rate
- || mPrevHeader.stream_number != hdr.stream_number) {
-
- if (mPrevHeaderValid) {
- LOG(INFO) << "Found audio data in a different configuration than before!";
-
- // reset?
- return;
- }
-
- mPrevHeaderValid = true;
- mPrevHeader = hdr;
-
- CHECK_EQ(aacEncoder_SetParam(
- mImpl, AACENC_AOT, kAACProfile), AACENC_OK);
-
- CHECK_EQ(aacEncoder_SetParam(
- mImpl, AACENC_SAMPLERATE, hdr.frame_rate), AACENC_OK);
-
- CHECK_EQ(aacEncoder_SetParam(mImpl, AACENC_BITRATE, 128000), AACENC_OK);
-
- const size_t numChannels = hdr.frame_size / sizeof(int16_t);
- CHECK(numChannels == 1 || numChannels == 2);
-
- mChannelCount = numChannels;
-
- CHECK_EQ(aacEncoder_SetParam(
- mImpl,
- AACENC_CHANNELMODE,
- (numChannels == 1) ? MODE_1 : MODE_2),
- AACENC_OK);
-
- CHECK_EQ(aacEncoder_SetParam(
- mImpl, AACENC_TRANSMUX, TT_MP4_RAW), AACENC_OK);
-
- CHECK_EQ(aacEncEncode(
- mImpl, nullptr, nullptr, nullptr, nullptr), AACENC_OK);
-
- AACENC_InfoStruct encInfo;
- CHECK_EQ(aacEncInfo(mImpl, &encInfo), AACENC_OK);
-
- mConfig = new ABuffer(encInfo.confSize);
- memcpy(mConfig->data(), encInfo.confBuf, encInfo.confSize);
-
- // hexdump(mConfig->data(), mConfig->size(), 0, nullptr);
-
- if (!mUseADTSFraming) {
- if (mOnFrameFn) {
- mOnFrameFn(mConfig);
- }
- } else {
- CHECK(GetSampleRateIndex(hdr.frame_rate, &mADTSSampleRateIndex));
- }
-
- const size_t numBytesPerInputFrame =
- numChannels * 1024 * sizeof(int16_t);
-
- mInputFrame = new ABuffer(numBytesPerInputFrame);
- mInputFrame->setRange(0, 0);
- }
-
- size_t offset = sizeof(gce_audio_message);
- while (offset < size) {
- if (mInputFrame->size() == 0) {
- mInputFrame->meta()->setInt64("timeUs", timeUs);
- }
-
- size_t copy = std::min(
- size - offset, mInputFrame->capacity() - mInputFrame->size());
-
- memcpy(mInputFrame->data() + mInputFrame->size(), &data[offset], copy);
- mInputFrame->setRange(0, mInputFrame->size() + copy);
-
- offset += copy;
-
- // "Time" on the input data has in effect advanced by the
- // number of audio frames we just advanced offset by.
- timeUs +=
- (copy * 1000000ll / hdr.frame_rate) / (mChannelCount * sizeof(int16_t));
-
- if (mInputFrame->size() == mInputFrame->capacity()) {
- void *inBuffers[] = { nullptr };
- INT inBufferIds[] = { IN_AUDIO_DATA };
- INT inBufferSizes[] = { 0 };
- INT inBufferElSizes[] = { sizeof(int16_t) };
-
- AACENC_BufDesc inBufDesc;
- inBufDesc.numBufs = sizeof(inBuffers) / sizeof(inBuffers[0]);
- inBufDesc.bufs = inBuffers;
- inBufDesc.bufferIdentifiers = inBufferIds;
- inBufDesc.bufSizes = inBufferSizes;
- inBufDesc.bufElSizes = inBufferElSizes;
-
- static constexpr size_t kMaxFrameSize = 8192;
- static constexpr size_t kADTSHeaderSize = 7;
-
- sp<ABuffer> outBuffer =
- new ABuffer(
- mUseADTSFraming
- ? kMaxFrameSize + kADTSHeaderSize : kMaxFrameSize);
-
- if (mUseADTSFraming) {
- outBuffer->setRange(0, kADTSHeaderSize);
- } else {
- outBuffer->setRange(0, 0);
- }
-
- void *outBuffers[] = { nullptr };
- INT outBufferIds[] = { OUT_BITSTREAM_DATA };
- INT outBufferSizes[] = { 0 };
- INT outBufferElSizes[] = { sizeof(UCHAR) };
-
- AACENC_BufDesc outBufDesc;
- outBufDesc.numBufs = sizeof(outBuffers) / sizeof(outBuffers[0]);
- outBufDesc.bufs = outBuffers;
- outBufDesc.bufferIdentifiers = outBufferIds;
- outBufDesc.bufSizes = outBufferSizes;
- outBufDesc.bufElSizes = outBufferElSizes;
-
- size_t inSampleOffset = 0;
- do {
- AACENC_InArgs inArgs;
- AACENC_OutArgs outArgs;
- memset(&inArgs, 0, sizeof(inArgs));
- memset(&outArgs, 0, sizeof(outArgs));
-
- inArgs.numInSamples =
- mInputFrame->size() / sizeof(int16_t) - inSampleOffset;
-
- inBuffers[0] =
- mInputFrame->data() + inSampleOffset * sizeof(int16_t);
-
- inBufferSizes[0] = inArgs.numInSamples * sizeof(int16_t);
-
- outBuffers[0] = outBuffer->data() + outBuffer->size();
- outBufferSizes[0] = outBuffer->capacity() - outBuffer->size();
-
- CHECK_EQ(aacEncEncode(
- mImpl, &inBufDesc, &outBufDesc, &inArgs, &outArgs),
- AACENC_OK);
-
- outBuffer->setRange(
- 0, outBuffer->size() + outArgs.numOutBytes);
-
- inSampleOffset += outArgs.numInSamples;
- } while (inSampleOffset < (mInputFrame->size() / sizeof(int16_t)));
-
- int64_t inputFrameTimeUs;
- CHECK(mInputFrame->meta()->findInt64("timeUs", &inputFrameTimeUs));
- outBuffer->meta()->setInt64("timeUs", inputFrameTimeUs);
-
- mInputFrame->setRange(0, 0);
-
- if (mUseADTSFraming) {
- fillADTSHeader(outBuffer);
- }
-
-#if LOG_AUDIO
- fwrite(outBuffer->data(), 1, outBuffer->size(), mLogFile);
- fflush(mLogFile);
-#endif
-
- if (mOnFrameFn) {
- mOnFrameFn(outBuffer);
- }
- }
- }
-}
-
-void AudioSource::AACEncoder::fillADTSHeader(const sp<ABuffer> &outBuffer) const {
- static constexpr unsigned kADTSId = 0;
- static constexpr unsigned kADTSLayer = 0;
- static constexpr unsigned kADTSProtectionAbsent = 1;
-
- unsigned frameLength = outBuffer->size();
- uint8_t *dst = outBuffer->data();
-
- dst[0] = 0xff;
-
- dst[1] =
- 0xf0 | (kADTSId << 3) | (kADTSLayer << 1) | kADTSProtectionAbsent;
-
- dst[2] = ((kAACProfile - 1) << 6)
- | (mADTSSampleRateIndex << 2)
- | (mChannelCount >> 2);
-
- dst[3] = ((mChannelCount & 3) << 6) | (frameLength >> 11);
-
- dst[4] = (frameLength >> 3) & 0xff;
- dst[5] = (frameLength & 7) << 5;
- dst[6] = 0x00;
-}
-
-// static
-bool AudioSource::AACEncoder::GetSampleRateIndex(
- int32_t sampleRate, size_t *tableIndex) {
- static constexpr int32_t kSampleRateTable[] = {
- 96000, 88200, 64000, 48000, 44100, 32000,
- 24000, 22050, 16000, 12000, 11025, 8000
- };
- static constexpr size_t kNumSampleRates =
- sizeof(kSampleRateTable) / sizeof(kSampleRateTable[0]);
-
- *tableIndex = 0;
- for (size_t index = 0; index < kNumSampleRates; ++index) {
- if (sampleRate == kSampleRateTable[index]) {
- *tableIndex = index;
- return true;
- }
- }
-
- return false;
-}
-
////////////////////////////////////////////////////////////////////////////////
struct Upsampler {
@@ -568,13 +243,7 @@
return;
}
-#if 0
- int64_t timeUs =
- static_cast<int64_t>(hdr.time_presented.tv_sec) * 1000000ll
- + (hdr.time_presented.tv_nsec + 500) / 1000;
-#else
static int64_t timeUs = 0;
-#endif
static int64_t prevTimeUs = 0;
@@ -807,13 +476,7 @@
return;
}
-#if 0
- int64_t timeUs =
- static_cast<int64_t>(hdr.time_presented.tv_sec) * 1000000ll
- + (hdr.time_presented.tv_nsec + 500) / 1000;
-#else
static int64_t timeUs = 0;
-#endif
static int64_t prevTimeUs = 0;
@@ -976,12 +639,6 @@
#endif
{
switch (format) {
- case Format::AAC:
- {
- mEncoder.reset(new AACEncoder(useADTSFraming));
- break;
- }
-
case Format::OPUS:
{
CHECK(!useADTSFraming);
diff --git a/host/frontend/gcastv2/libsource/BufferQueue.cpp b/host/frontend/gcastv2/libsource/BufferQueue.cpp
deleted file mode 100644
index ae1a121..0000000
--- a/host/frontend/gcastv2/libsource/BufferQueue.cpp
+++ /dev/null
@@ -1,111 +0,0 @@
-#include <source/BufferQueue.h>
-
-#include <media/stagefright/foundation/ALooper.h>
-
-namespace android {
-
-BufferQueue::BufferQueue(size_t count, size_t size)
- : mInitCheck(NO_INIT),
- mBufferSize(size) {
- for (size_t i = 0; i < count; ++i) {
- void *buffer = malloc(size);
- if (buffer == nullptr) {
- mInitCheck = -ENOMEM;
- return;
- }
-
- mEmptyBuffers.push_back(buffer);
- }
-
- mInitCheck = OK;
-}
-
-BufferQueue::~BufferQueue() {
- for (auto buffer : mEmptyBuffers) {
- free(buffer);
- }
-}
-
-status_t BufferQueue::initCheck() const {
- return mInitCheck;
-}
-
-size_t BufferQueue::bufferSize() const {
- return mBufferSize;
-}
-
-void *BufferQueue::acquire(int64_t timeoutUs) {
- int64_t waitUntilUs =
- (timeoutUs < 0ll) ? -1ll : ALooper::GetNowUs() + timeoutUs;
-
- std::unique_lock<std::mutex> autoLock(mLock);
- while (mEmptyBuffers.empty()) {
- if (waitUntilUs < 0ll) {
- mCondition.wait(autoLock);
- } else {
- int64_t nowUs = ALooper::GetNowUs();
-
- if (nowUs >= waitUntilUs) {
- break;
- }
-
- auto result = mCondition.wait_for(
- autoLock, std::chrono::microseconds(waitUntilUs - nowUs));
-
- if (result == std::cv_status::timeout) {
- break;
- }
- }
- }
-
- if (mEmptyBuffers.empty()) {
- return nullptr;
- }
-
- auto result = mEmptyBuffers.front();
- mEmptyBuffers.pop_front();
-
- return result;
-}
-
-void BufferQueue::queue(void *data) {
- std::lock_guard<std::mutex> autoLock(mLock);
- bool wasEmpty = mFullBuffers.empty();
- mFullBuffers.push_back(Buffer { data, 0 /* offset */ });
- if (wasEmpty) {
- mCondition.notify_all();
- }
-}
-
-void *BufferQueue::dequeueBegin(size_t *size) {
- std::lock_guard<std::mutex> autoLock(mLock);
- if (mFullBuffers.empty()) {
- return nullptr;
- }
-
- Buffer &result = mFullBuffers.front();
- *size = mBufferSize - result.mOffset;
-
- return static_cast<uint8_t *>(result.mData) + result.mOffset;
-}
-
-void BufferQueue::dequeueEnd(size_t size) {
- std::lock_guard<std::mutex> autoLock(mLock);
- CHECK(!mFullBuffers.empty());
- Buffer &result = mFullBuffers.front();
- CHECK_LE(size, mBufferSize - result.mOffset);
- result.mOffset = mBufferSize - size;
- if (size == 0) {
- bool wasEmpty = mEmptyBuffers.empty();
- mEmptyBuffers.push_back(result.mData);
-
- if (wasEmpty) {
- mCondition.notify_all();
- }
-
- mFullBuffers.pop_front();
- }
-}
-
-} // namespace android
-
diff --git a/host/frontend/gcastv2/libsource/CameraSource.cpp b/host/frontend/gcastv2/libsource/CameraSource.cpp
deleted file mode 100644
index 55e0755..0000000
--- a/host/frontend/gcastv2/libsource/CameraSource.cpp
+++ /dev/null
@@ -1,185 +0,0 @@
-#include <source/CameraSource.h>
-
-#include <media/stagefright/MediaDefs.h>
-#include <media/stagefright/avc_utils.h>
-#include <media/stagefright/foundation/ABuffer.h>
-#include <media/stagefright/foundation/ADebug.h>
-#include <media/stagefright/foundation/AMessage.h>
-#include <media/stagefright/foundation/TSPacketizer.h>
-
-namespace android {
-
-CameraSource::CameraSource()
- : mInitCheck(NO_INIT),
- mState(STOPPED),
- mSession(createCameraSession(&CameraSource::onFrameData, this)) {
- mInitCheck = OK;
-}
-
-CameraSource::~CameraSource() {
- stop();
-
- destroyCameraSession(mSession);
- mSession = nullptr;
-}
-
-status_t CameraSource::initCheck() const {
- return mInitCheck;
-}
-
-sp<AMessage> CameraSource::getFormat() const {
- return nullptr;
-}
-
-status_t CameraSource::start() {
- std::lock_guard<std::mutex> autoLock(mLock);
-
- if (mState != STOPPED) {
- return OK;
- }
-
- mState = RUNNING;
- startCameraSession(mSession);
-
- return OK;
-}
-
-status_t CameraSource::stop() {
- std::lock_guard<std::mutex> autoLock(mLock);
-
- if (mState == STOPPED) {
- return OK;
- }
-
- mState = STOPPED;
- stopCameraSession(mSession);
-
- return OK;
-}
-
-status_t CameraSource::pause() {
- std::lock_guard<std::mutex> autoLock(mLock);
-
- if (mState == PAUSED) {
- return OK;
- }
-
- if (mState != RUNNING) {
- return INVALID_OPERATION;
- }
-
- mState = PAUSED;
- pauseCameraSession(mSession);
-
- ALOGI("Now paused.");
-
- return OK;
-}
-
-status_t CameraSource::resume() {
- std::lock_guard<std::mutex> autoLock(mLock);
-
- if (mState == RUNNING) {
- return OK;
- }
-
- if (mState != PAUSED) {
- return INVALID_OPERATION;
- }
-
- mState = RUNNING;
- resumeCameraSession(mSession);
-
- ALOGI("Now running.");
-
- return OK;
-}
-
-bool CameraSource::paused() const {
- return mState == PAUSED;
-}
-
-status_t CameraSource::requestIDRFrame() {
- return OK;
-}
-
-// static
-void CameraSource::onFrameData(
- void *cookie,
- ssize_t csdIndex,
- int64_t timeUs,
- const void *data,
- size_t size) {
- return static_cast<CameraSource *>(cookie)->onFrameData(
- csdIndex, timeUs, data, size);
-}
-
-static uint32_t U32BE_AT(const void *_data) {
- const uint8_t *data = (const uint8_t *)_data;
- return data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
-}
-
-void CameraSource::onFrameData(
- ssize_t csdIndex, int64_t timeUs, const void *_data, size_t size) {
- const uint8_t *data = static_cast<const uint8_t *>(_data);
-
- ALOGV("got frame data csdIndex=%zd at %lld us, data %p, size %zu",
- csdIndex, timeUs, data, size);
-
- if (csdIndex >= 0) {
- sp<ABuffer> csd = new ABuffer(4 + size);
- memcpy(csd->data(), "\x00\x00\x00\x01", 4);
- memcpy(csd->data() + 4, data, size);
-
- mCSD.push_back(csd);
- return;
- }
-
- sp<ABuffer> accessUnit = new ABuffer(size);
- memcpy(accessUnit->data(), data, size);
-
- size_t offset = 0;
- while (offset + 3 < size) {
- uint32_t naluLength = U32BE_AT(&data[offset]);
- CHECK_LE(offset + 4 + naluLength, size);
-
- memcpy(accessUnit->data() + offset, "\x00\x00\x00\x01", 4);
-
- offset += 4;
- // ALOGI("nalType 0x%02x", data[offset] & 0x1f);
-
- CHECK_GT(naluLength, 0u);
- offset += naluLength;
- }
- CHECK_EQ(offset, size);
-
- if (IsIDR(accessUnit)) {
- accessUnit = prependCSD(accessUnit);
- }
-
- accessUnit->meta()->setInt64("timeUs", timeUs);
-
- sp<AMessage> notify = mNotify->dup();
- notify->setBuffer("accessUnit", accessUnit);
- notify->post();
-}
-
-sp<ABuffer> CameraSource::prependCSD(const sp<ABuffer> &accessUnit) const {
- size_t size = 0;
- for (const auto &csd : mCSD) {
- size += csd->size();
- }
-
- sp<ABuffer> dup = new ABuffer(accessUnit->size() + size);
- size_t offset = 0;
- for (const auto &csd : mCSD) {
- memcpy(dup->data() + offset, csd->data(), csd->size());
- offset += csd->size();
- }
-
- memcpy(dup->data() + offset, accessUnit->data(), accessUnit->size());
-
- return dup;
-}
-
-} // namespace android
diff --git a/host/frontend/gcastv2/libsource/CameraSourceSupport.h b/host/frontend/gcastv2/libsource/CameraSourceSupport.h
deleted file mode 100644
index 9005921..0000000
--- a/host/frontend/gcastv2/libsource/CameraSourceSupport.h
+++ /dev/null
@@ -1,45 +0,0 @@
-#pragma once
-
-#import <AVFoundation/AVFoundation.h>
-#import <Foundation/Foundation.h>
-#import <VideoToolbox/VideoToolbox.h>
-
-typedef void (*CameraSessionCallback)(
- void *cookie,
- ssize_t csdIndex,
- int64_t timeUs,
- const void *data,
- size_t size);
-
-@interface MyVideoOutputDelegate
- : NSObject <AVCaptureVideoDataOutputSampleBufferDelegate> {
- BOOL first_;
-
- CameraSessionCallback cb_;
- void *cookie_;
- BOOL paused_;
-
-#ifdef TARGET_IOS
- VTCompressionSessionRef compressionSession_;
-#endif
-}
-
--(id)initWithCallback:(CameraSessionCallback)cb cookie:(void *)cookie;
--(void)pause;
--(void)resume;
-
-@end
-
-@interface MyCameraSession : NSObject {
- AVCaptureSession *session_;
- AVCaptureDevice *camera_;
- dispatch_queue_t dispatchQueue_;
- MyVideoOutputDelegate *delegate_;
-}
-
--(id)initWithCallback:(CameraSessionCallback)cb cookie:(void *)cookie;
--(void)pause;
--(void)resume;
-
-@end
-
diff --git a/host/frontend/gcastv2/libsource/CameraSourceSupport.m b/host/frontend/gcastv2/libsource/CameraSourceSupport.m
deleted file mode 100644
index 5835935..0000000
--- a/host/frontend/gcastv2/libsource/CameraSourceSupport.m
+++ /dev/null
@@ -1,270 +0,0 @@
-#import "CameraSourceSupport.h"
-
-@implementation MyVideoOutputDelegate
-
--(id)initWithCallback:(CameraSessionCallback)cb cookie:(void *)cookie {
- if ((self = [super init]) != nil) {
- first_ = YES;
-
- cb_ = cb;
- cookie_ = cookie;
-
- paused_ = false;
-
-#ifdef TARGET_IOS
- compressionSession_ = nil;
-#endif
- }
-
- return self;
-}
-
--(void)pause {
- paused_ = true;
-}
-
--(void)resume {
- paused_ = false;
-}
-
--(void)onCompressedFrame:(CMSampleBufferRef)buffer {
- if (first_) {
- first_ = NO;
-
- CMFormatDescriptionRef format =
- CMSampleBufferGetFormatDescription(buffer);
-
- size_t numParameterSets;
- OSStatus err = CMVideoFormatDescriptionGetH264ParameterSetAtIndex(
- format, 0 /* index */, NULL, NULL, &numParameterSets, NULL);
- NSAssert(
- err == noErr,
- @"CMVideoFormatDescriptionGetH264ParameterSetAtIndex failed");
-
- const uint8_t *params;
- size_t paramsSize;
- for (size_t i = 0; i < numParameterSets; ++i) {
- err = CMVideoFormatDescriptionGetH264ParameterSetAtIndex(
- format, i, ¶ms, ¶msSize, NULL, NULL);
- NSAssert(
- err == noErr,
- @"CMVideoFormatDescriptionGetH264ParameterSetAtIndex failed");
-
- cb_(cookie_, i, 0ll, params, paramsSize);
- }
- }
-
- CMItemCount numSamples = CMSampleBufferGetNumSamples(buffer);
- NSAssert(numSamples == 1, @"expected a single sample");
-
- CMBlockBufferRef blockBuffer = CMSampleBufferGetDataBuffer(buffer);
-
- size_t sampleSize = CMSampleBufferGetSampleSize(buffer, 0 /* index */);
-
- size_t lengthAtOffset;
- size_t totalLength;
- char *ptr;
- OSStatus err = CMBlockBufferGetDataPointer(
- blockBuffer, 0 /* offset */, &lengthAtOffset, &totalLength, &ptr);
- NSAssert(err == kCMBlockBufferNoErr, @"CMBlockBufferGetDataPointer failed");
- NSAssert(lengthAtOffset == sampleSize, @"sampleSize mismatch");
- NSAssert(lengthAtOffset <= totalLength, @"totalLength mismatch");
-
- // NSLog(@" sample has size %zu, ptr:%p", sampleSize, ptr);
-
- CMSampleTimingInfo info;
- err = CMSampleBufferGetSampleTimingInfo(buffer, 0 /* sampleIndex */, &info);
- NSAssert(err == noErr, @"CMSampleBufferGetSampleTimingInfo failed");
-
- const int64_t timeUs =
- (int64_t)(CMTimeGetSeconds(info.presentationTimeStamp) * 1e6);
-
- cb_(cookie_, -1, timeUs, ptr, sampleSize);
-}
-
-#ifdef TARGET_IOS
--(void)dealloc {
- VTCompressionSessionInvalidate(compressionSession_);
- compressionSession_ = nil;
-}
-
-void CompressionCallback(
- void *cookie,
- void *sourceFrameRefCon,
- OSStatus status,
- VTEncodeInfoFlags infoFlags,
- CMSampleBufferRef buffer) {
- [(__bridge MyVideoOutputDelegate *)cookie onCompressedFrame:buffer];
-}
-
--(void)captureOutput:(AVCaptureOutput *)output
- didOutputSampleBuffer:(CMSampleBufferRef)buffer
- fromConnection:(AVCaptureConnection *)connection {
- if (paused_) {
- return;
- }
-
- CMFormatDescriptionRef format =
- CMSampleBufferGetFormatDescription(buffer);
-
- if (compressionSession_ == nil) {
- CMVideoDimensions dim = CMVideoFormatDescriptionGetDimensions(format);
-
- OSStatus err = VTCompressionSessionCreate(
- kCFAllocatorDefault,
- dim.width,
- dim.height,
- kCMVideoCodecType_H264,
- NULL /* encoderSettings */,
- NULL /* sourceImageBufferAttributes */,
- kCFAllocatorDefault,
- CompressionCallback,
- (__bridge void *)self,
- &compressionSession_);
-
- NSAssert(err == noErr, @"VTCompressionSessionCreate failed");
- }
-
- CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(buffer);
-
- CMSampleTimingInfo info;
- OSStatus err = CMSampleBufferGetSampleTimingInfo(buffer, 0 /* sampleIndex */, &info);
- NSAssert(err == noErr, @"CMSampleBufferGetSampleTimingInfo failed");
-
- VTEncodeInfoFlags infoFlags;
- err = VTCompressionSessionEncodeFrame(
- compressionSession_,
- imageBuffer,
- info.presentationTimeStamp,
- info.duration,
- NULL /* frameProperties */,
- NULL /* sourceFrameRefCon */,
- &infoFlags);
-
- NSAssert(err == noErr, @"VTCompressionSessionEncodeFrame failed");
-}
-#else
--(void)captureOutput:(AVCaptureOutput *)output
- didOutputSampleBuffer:(CMSampleBufferRef)buffer
- fromConnection:(AVCaptureConnection *)connection {
- [self onCompressedFrame:buffer];
-}
-#endif
-
--(void)captureOutput:(AVCaptureOutput *)output
- didDropSampleBuffer:(CMSampleBufferRef)buffer
- fromConnection:(AVCaptureConnection *)connection {
- NSLog(@"Dropped a frame!");
-}
-
-@end
-
-@implementation MyCameraSession
-
--(id)initWithCallback:(CameraSessionCallback)cb cookie:(void *)cookie {
- if ((self = [super init]) != nil) {
- dispatchQueue_ = dispatch_queue_create(
- "CameraSource", DISPATCH_QUEUE_SERIAL);
-
- session_ = [AVCaptureSession new];
- session_.sessionPreset = AVCaptureSessionPreset1280x720;
-
- [session_ beginConfiguration];
-
-#ifdef TARGET_IOS
- [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo
- completionHandler:^(BOOL granted) {
- NSLog(@"XXX granted = %d", granted);
- }];
-
- camera_ = [AVCaptureDevice defaultDeviceWithDeviceType:AVCaptureDeviceTypeBuiltInDualCamera mediaType:AVMediaTypeVideo position:AVCaptureDevicePositionFront];
-
- if (camera_ == nil) {
- camera_ = [AVCaptureDevice defaultDeviceWithDeviceType:AVCaptureDeviceTypeBuiltInWideAngleCamera mediaType:AVMediaTypeVideo position:AVCaptureDevicePositionFront];
- }
-#else
- camera_ = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
-#endif
-
- NSLog(@"camera supports the following frame rates: %@",
- camera_.activeFormat.videoSupportedFrameRateRanges);
-
- camera_.activeVideoMinFrameDuration = CMTimeMake(1, 30); // limit to 30fps
-
- NSError *error;
- AVCaptureDeviceInput *videoInput =
- [AVCaptureDeviceInput deviceInputWithDevice:camera_ error:&error];
-
- AVCaptureVideoDataOutput *videoOutput = [AVCaptureVideoDataOutput new];
-
- // NSLog(@"available codec types: %@", videoOutput.availableVideoCodecTypes);
- // NSLog(@"available cvpixel types: %@", videoOutput.availableVideoCVPixelFormatTypes);
-
-#if defined(TARGET_IOS)
- videoOutput.videoSettings = nil;
-#else
- videoOutput.videoSettings =
- [NSDictionary dictionaryWithObjectsAndKeys:
- AVVideoCodecTypeH264, AVVideoCodecKey,
- nil, nil];
-#endif
-
- delegate_ =
- [[MyVideoOutputDelegate alloc] initWithCallback:cb cookie:cookie];
-
- [videoOutput
- setSampleBufferDelegate:delegate_
- queue:dispatchQueue_];
-
- [session_ addInput:videoInput];
- [session_ addOutput:videoOutput];
-
- [session_ commitConfiguration];
- }
-
- return self;
-}
-
--(void)start {
- [session_ startRunning];
-}
-
--(void)stop {
- [session_ stopRunning];
-}
-
--(void)pause {
- [delegate_ pause];
-}
-
--(void)resume {
- [delegate_ resume];
-}
-
-@end
-
-void *createCameraSession(CameraSessionCallback cb, void *cookie) {
- return (void *)(CFBridgingRetain([[MyCameraSession alloc] initWithCallback:cb cookie:cookie]));
-}
-
-void startCameraSession(void *session) {
- [(__bridge MyCameraSession *)session start];
-}
-
-void stopCameraSession(void *session) {
- [(__bridge MyCameraSession *)session stop];
-}
-
-void pauseCameraSession(void *session) {
- [(__bridge MyCameraSession *)session pause];
-}
-
-void resumeCameraSession(void *session) {
- [(__bridge MyCameraSession *)session resume];
-}
-
-void destroyCameraSession(void *session) {
- CFBridgingRelease(session);
-}
-
-
diff --git a/host/frontend/gcastv2/libsource/DirectRenderer_iOS.cpp b/host/frontend/gcastv2/libsource/DirectRenderer_iOS.cpp
deleted file mode 100644
index 3c22213..0000000
--- a/host/frontend/gcastv2/libsource/DirectRenderer_iOS.cpp
+++ /dev/null
@@ -1,221 +0,0 @@
-#include <source/DirectRenderer_iOS.h>
-
-#include <media/stagefright/avc_utils.h>
-#include <media/stagefright/foundation/ABuffer.h>
-#include <media/stagefright/foundation/AMessage.h>
-
-namespace android {
-
-DirectRenderer_iOS::DirectRenderer_iOS()
- : mVideoFormatDescription(nullptr),
- mSession(nullptr) {
-}
-
-DirectRenderer_iOS::~DirectRenderer_iOS() {
- if (mVideoFormatDescription) {
- CFRelease(mVideoFormatDescription);
- mVideoFormatDescription = NULL;
- }
-
- if (mSession) {
- VTDecompressionSessionInvalidate(mSession);
- CFRelease(mSession);
- mSession = NULL;
- }
-}
-
-static void OnFrameReady(
- void *decompressionOutputRefCon,
- void *sourceFrameRefCon,
- OSStatus status,
- VTDecodeInfoFlags infoFlags,
- CVImageBufferRef imageBuffer,
- CMTime presentationTimeStamp,
- CMTime presentationDuration) {
- static_cast<DirectRenderer_iOS *>(
- decompressionOutputRefCon)->render(imageBuffer);
-}
-
-void DirectRenderer_iOS::setFormat(size_t index, const sp<AMessage> &format) {
- ALOGI("DirectRenderer_iOS::setFormat(%zu) => %s",
- index,
- format->debugString().c_str());
-
- sp<ABuffer> csd0;
- CHECK(format->findBuffer("csd-0", &csd0));
- CHECK(csd0->size() >= 4 && !memcmp(csd0->data(), "\x00\x00\x00\x01", 4));
-
- sp<ABuffer> csd1;
- CHECK(format->findBuffer("csd-1", &csd1));
- CHECK(csd1->size() >= 4 && !memcmp(csd1->data(), "\x00\x00\x00\x01", 4));
-
- int32_t width, height;
- CHECK(format->findInt32("width", &width));
- CHECK(format->findInt32("height", &height));
-
- const uint8_t *parameterSets[2] = {
- csd0->data() + 4,
- csd1->data() + 4,
- };
-
- const size_t parameterSetSizes[2] = {
- csd0->size() - 4,
- csd1->size() - 4,
- };
-
- OSStatus status = CMVideoFormatDescriptionCreateFromH264ParameterSets(
- kCFAllocatorDefault,
- sizeof(parameterSets) / sizeof(parameterSets[0]),
- parameterSets,
- parameterSetSizes,
- 4 /* NALUnitHeaderLength */,
- &mVideoFormatDescription);
-
- CHECK_EQ(status, noErr);
-
- CFDictionaryRef videoDecoderSpecification = NULL;
-
- CFMutableDictionaryRef destinationImageBufferAttrs =
- CFDictionaryCreateMutable(
- kCFAllocatorDefault,
- 0 /* capacity */,
- &kCFTypeDictionaryKeyCallBacks,
- &kCFTypeDictionaryValueCallBacks);
-
- CFDictionarySetValue(
- destinationImageBufferAttrs,
- kCVPixelBufferOpenGLESCompatibilityKey,
- kCFBooleanTrue);
-
- SInt32 pixelType = kCVPixelFormatType_32BGRA;
-
- CFNumberRef value =
- CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &pixelType);
-
- CFDictionarySetValue(
- destinationImageBufferAttrs,
- kCVPixelBufferPixelFormatTypeKey,
- value);
-
- CFRelease(value);
-
- CFDictionaryRef surfaceProps =
- CFDictionaryCreate(
- kCFAllocatorDefault,
- NULL /* keys */,
- NULL /* values */,
- 0 /* numValues */,
- &kCFTypeDictionaryKeyCallBacks,
- &kCFTypeDictionaryValueCallBacks);
-
- CFDictionarySetValue(
- destinationImageBufferAttrs,
- kCVPixelBufferIOSurfacePropertiesKey,
- surfaceProps);
-
- CFRelease(surfaceProps);
- surfaceProps = NULL;
-
- VTDecompressionOutputCallbackRecord outputCallback = {
- .decompressionOutputCallback = OnFrameReady,
- .decompressionOutputRefCon = this,
- };
-
- status = VTDecompressionSessionCreate(
- kCFAllocatorDefault,
- mVideoFormatDescription,
- videoDecoderSpecification,
- destinationImageBufferAttrs,
- &outputCallback,
- &mSession);
-
- CHECK_EQ(status, noErr);
-}
-
-static sp<ABuffer> ReplaceStartCodesWithLength(const sp<ABuffer> &buffer) {
- sp<ABuffer> outBuf = new ABuffer(buffer->size() + 128); // Replacing 2 byte length with 4 byte startcodes takes its toll...
- uint8_t *outData = outBuf->data();
- size_t outOffset = 0;
-
- const uint8_t *data = buffer->data();
- size_t size = buffer->size();
-
- const uint8_t *nalStart;
- size_t nalSize;
- while (getNextNALUnit(&data, &size, &nalStart, &nalSize, true) == OK) {
- outData[outOffset++] = (nalSize >> 24) & 0xff;
- outData[outOffset++] = (nalSize >> 16) & 0xff;
- outData[outOffset++] = (nalSize >> 8) & 0xff;
- outData[outOffset++] = nalSize & 0xff;
- memcpy(&outData[outOffset], nalStart, nalSize);
- outOffset += nalSize;
- }
-
- outBuf->setRange(0, outOffset);
-
- return outBuf;
-}
-
-void DirectRenderer_iOS::queueAccessUnit(
- size_t index, const sp<ABuffer> &accessUnit) {
- sp<ABuffer> sampleBuf = ReplaceStartCodesWithLength(accessUnit);
-
- CMBlockBufferRef blockBuffer;
- OSStatus status = CMBlockBufferCreateWithMemoryBlock(
- kCFAllocatorDefault,
- sampleBuf->data(),
- sampleBuf->size(),
- kCFAllocatorNull,
- NULL /* customBlockSource */,
- 0 /* offsetToData */,
- sampleBuf->size(),
- 0 /* flags */,
- &blockBuffer);
-
- int64_t timeUs;
- CHECK(accessUnit->meta()->findInt64("timeUs", &timeUs));
-
- const CMSampleTimingInfo timing = {
- .duration = 0,
- .presentationTimeStamp = CMTimeMake((timeUs * 9ll) / 100ll, 90000),
- .decodeTimeStamp = kCMTimeInvalid,
- };
-
- const size_t size = sampleBuf->size();
-
- CMSampleBufferRef sampleBuffer;
- status = CMSampleBufferCreate(
- kCFAllocatorDefault,
- blockBuffer,
- true /* dataReady */,
- NULL /* makeDataReadyCallback */,
- 0 /* makeDataReadyRefCon */,
- mVideoFormatDescription,
- 1 /* numSamples */,
- 1 /* numSampleTimingEntries */,
- &timing /* sampleTimingArray */,
- 1 /* numSampleSizeEntries */,
- &size /* sampleSizeArray */,
- &sampleBuffer);
-
- CFRelease(blockBuffer);
- blockBuffer = NULL;
-
- CHECK_EQ(status, noErr);
-
- // NSLog(@"got a buffer of size %zu\n", sampleBuf->size());
-
- VTDecodeInfoFlags infoFlags;
- status = VTDecompressionSessionDecodeFrame(
- mSession,
- sampleBuffer,
- kVTDecodeFrame_EnableAsynchronousDecompression
- | kVTDecodeFrame_EnableTemporalProcessing,
- 0 /* sourceFrameRefCon */,
- &infoFlags);
-
- CFRelease(sampleBuffer);
- sampleBuffer = NULL;
-}
-
-} // namespace android
diff --git a/host/frontend/gcastv2/libsource/DisplayListsSource.cpp b/host/frontend/gcastv2/libsource/DisplayListsSource.cpp
deleted file mode 100644
index e84bc09..0000000
--- a/host/frontend/gcastv2/libsource/DisplayListsSource.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-#include <source/DisplayListsSource.h>
-
-#include <media/stagefright/foundation/ABuffer.h>
-#include <media/stagefright/foundation/AMessage.h>
-
-namespace android {
-
-status_t DisplayListsSource::initCheck() const {
- return OK;
-}
-
-sp<AMessage> DisplayListsSource::getFormat() const {
- return nullptr;
-}
-
-status_t DisplayListsSource::start() {
- return OK;
-}
-
-status_t DisplayListsSource::stop() {
- return OK;
-}
-
-status_t DisplayListsSource::requestIDRFrame() {
- return OK;
-}
-
-void DisplayListsSource::inject(const void *data, size_t size) {
- sp<ABuffer> accessUnit = new ABuffer(size);
- memcpy(accessUnit->data(), data, size);
-
- accessUnit->meta()->setInt64("timeUs", ALooper::GetNowUs());
-
- StreamingSource::onAccessUnit(accessUnit);
-}
-
-} // namespace android
-
diff --git a/host/frontend/gcastv2/libsource/HostToGuestComms.cpp b/host/frontend/gcastv2/libsource/HostToGuestComms.cpp
index d704bfd..42910f2 100644
--- a/host/frontend/gcastv2/libsource/HostToGuestComms.cpp
+++ b/host/frontend/gcastv2/libsource/HostToGuestComms.cpp
@@ -1,17 +1,9 @@
-#ifdef TARGET_ANDROID_DEVICE_NO_JAVA
-#include "HostToGuestComms.h"
-#else
#include <source/HostToGuestComms.h>
-#endif
#include <https/SafeCallbackable.h>
#include <https/Support.h>
-#ifdef TARGET_ANDROID_DEVICE_NO_JAVA
-#include <android-base/logging.h>
-#else
#include <media/stagefright/foundation/ADebug.h>
-#endif
HostToGuestComms::HostToGuestComms(
std::shared_ptr<RunLoop> runLoop,
diff --git a/host/frontend/gcastv2/libsource/TouchSource.cpp b/host/frontend/gcastv2/libsource/TouchSource.cpp
deleted file mode 100644
index 55d57ac..0000000
--- a/host/frontend/gcastv2/libsource/TouchSource.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-#include <source/TouchSource.h>
-
-#include <media/stagefright/foundation/ABuffer.h>
-#include <media/stagefright/foundation/AMessage.h>
-
-namespace android {
-
-status_t TouchSource::initCheck() const {
- return OK;
-}
-
-sp<AMessage> TouchSource::getFormat() const {
- return nullptr;
-}
-
-status_t TouchSource::start() {
- return OK;
-}
-
-status_t TouchSource::stop() {
- return OK;
-}
-
-status_t TouchSource::requestIDRFrame() {
- return OK;
-}
-
-void TouchSource::inject(bool down, int32_t x, int32_t y) {
- sp<ABuffer> accessUnit = new ABuffer(3 * sizeof(int32_t));
- int32_t *data = reinterpret_cast<int32_t *>(accessUnit->data());
- data[0] = down;
- data[1] = x;
- data[2] = y;
-
- accessUnit->meta()->setInt64("timeUs", ALooper::GetNowUs());
-
- StreamingSource::onAccessUnit(accessUnit);
-}
-
-} // namespace android
-
diff --git a/host/frontend/gcastv2/libsource/VideoSink.cpp b/host/frontend/gcastv2/libsource/VideoSink.cpp
deleted file mode 100644
index 108b869..0000000
--- a/host/frontend/gcastv2/libsource/VideoSink.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-#include <source/VideoSink.h>
-
-#include <media/stagefright/avc_utils.h>
-#include <media/stagefright/Utils.h>
-#include <media/stagefright/MetaData.h>
-
-namespace android {
-
-VideoSink::VideoSink()
- : mRenderer(new DirectRenderer_iOS),
- mFirstAccessUnit(true) {
-}
-
-void VideoSink::onMessageReceived(const sp<AMessage> &msg) {
- switch (msg->what()) {
- case kWhatAccessUnit:
- {
- sp<ABuffer> accessUnit;
- CHECK(msg->findBuffer("accessUnit", &accessUnit));
-
- if (mFirstAccessUnit) {
- mFirstAccessUnit = false;
-
- sp<MetaData> meta = MakeAVCCodecSpecificData(accessUnit);
- CHECK(meta != nullptr);
-
- sp<AMessage> format;
- CHECK_EQ(OK, convertMetaDataToMessage(meta, &format));
-
- mRenderer->setFormat(0, format);
- }
-
- mRenderer->queueAccessUnit(0, accessUnit);
- break;
- }
-
- default:
- TRESPASS();
- }
-}
-
-} // namespace android
-
diff --git a/host/frontend/gcastv2/libsource/include/source/AACPlayer.h b/host/frontend/gcastv2/libsource/include/source/AACPlayer.h
deleted file mode 100644
index 208717c..0000000
--- a/host/frontend/gcastv2/libsource/include/source/AACPlayer.h
+++ /dev/null
@@ -1,61 +0,0 @@
-#pragma once
-
-#include "AudioQueueBufferManager.h"
-#include "BufferQueue.h"
-
-#include <utils/Errors.h>
-
-#include <sys/types.h>
-
-#include <AudioToolbox/AudioToolbox.h>
-
-#include <memory>
-
-namespace android {
-
-#define USE_AUDIO_UNIT 1
-
-struct AACPlayer {
- explicit AACPlayer();
- ~AACPlayer();
-
- AACPlayer(const AACPlayer &) = delete;
- AACPlayer &operator=(const AACPlayer &) = delete;
-
- status_t feedADTSFrame(const void *frame, size_t size);
-
- int32_t sampleRateHz() const;
-
-private:
- AudioStreamBasicDescription mInFormat, mOutFormat;
- AudioConverterRef mConverter;
-
-#if USE_AUDIO_UNIT
- AUGraph mGraph;
- AUNode mOutputNode;
- std::unique_ptr<BufferQueue> mBufferQueue;
-#else
- AudioQueueRef mQueue;
- std::unique_ptr<AudioQueueBufferManager> mBufferManager;
-#endif
-
- int32_t mSampleRateHz;
- int64_t mNumFramesSubmitted;
-
- status_t init(int32_t sampleRate, size_t channelCount);
-
-#if !USE_AUDIO_UNIT
- static void PlayCallback(
- void *_cookie, AudioQueueRef queue, AudioQueueBufferRef buffer);
-#else
- static OSStatus FeedInput(
- void *cookie,
- AudioUnitRenderActionFlags *flags,
- const AudioTimeStamp *timeStamp,
- UInt32 bus,
- UInt32 numFrames,
- AudioBufferList *data);
-#endif
-};
-
-} // namespace android
diff --git a/host/frontend/gcastv2/libsource/include/source/AudioQueueBufferManager.h b/host/frontend/gcastv2/libsource/include/source/AudioQueueBufferManager.h
deleted file mode 100644
index 0e4336c..0000000
--- a/host/frontend/gcastv2/libsource/include/source/AudioQueueBufferManager.h
+++ /dev/null
@@ -1,38 +0,0 @@
-#pragma once
-
-#include <utils/Errors.h>
-
-#include <AudioToolbox/AudioToolbox.h>
-
-#include <deque>
-#include <mutex>
-
-namespace android {
-
-struct AudioQueueBufferManager {
- AudioQueueBufferManager(AudioQueueRef queue, size_t count, size_t size);
- ~AudioQueueBufferManager();
-
- status_t initCheck() const;
-
- size_t bufferSize() const;
-
- AudioQueueBufferManager(const AudioQueueBufferManager &) = delete;
- AudioQueueBufferManager &operator=(const AudioQueueBufferManager &) = delete;
-
- AudioQueueBufferRef acquire(int64_t timeoutUs = -1ll);
- void release(AudioQueueBufferRef buffer);
-
-private:
- status_t mInitCheck;
- AudioQueueRef mQueue;
- size_t mBufferSize;
-
- std::mutex mLock;
- std::condition_variable mCondition;
-
- std::deque<AudioQueueBufferRef> mBuffers;
-};
-
-} // namespace android
-
diff --git a/host/frontend/gcastv2/libsource/include/source/AudioSink.h b/host/frontend/gcastv2/libsource/include/source/AudioSink.h
deleted file mode 100644
index ea46e2e..0000000
--- a/host/frontend/gcastv2/libsource/include/source/AudioSink.h
+++ /dev/null
@@ -1,25 +0,0 @@
-#pragma once
-
-#include <source/StreamingSink.h>
-
-#include "AACPlayer.h"
-
-#define LOG_AUDIO 0
-
-namespace android {
-
-struct AudioSink : public StreamingSink {
- AudioSink();
-
- void onMessageReceived(const sp<AMessage> &msg) override;
-
-private:
- std::unique_ptr<AACPlayer> mAACPlayer;
-
-#if LOG_AUDIO
- FILE *mFile;
-#endif
-};
-
-} // namespace android
-
diff --git a/host/frontend/gcastv2/libsource/include/source/AudioSource.h b/host/frontend/gcastv2/libsource/include/source/AudioSource.h
index 53217b0..82102c8 100644
--- a/host/frontend/gcastv2/libsource/include/source/AudioSource.h
+++ b/host/frontend/gcastv2/libsource/include/source/AudioSource.h
@@ -37,12 +37,11 @@
using AudioDataRegionView = vsoc::audio_data::AudioDataRegionView;
enum class Format {
- AAC,
OPUS,
G711_ALAW,
G711_ULAW,
};
- // ADTS framing is only supported for Format::AAC.
+ // ADTS framing is only supported for AAC.
explicit AudioSource(Format format, bool useADTSFraming = false);
AudioSource(const AudioSource &) = delete;
@@ -70,7 +69,6 @@
};
struct Encoder;
- struct AACEncoder;
struct OPUSEncoder;
struct G711Encoder;
diff --git a/host/frontend/gcastv2/libsource/include/source/BufferQueue.h b/host/frontend/gcastv2/libsource/include/source/BufferQueue.h
deleted file mode 100644
index ed11c5b..0000000
--- a/host/frontend/gcastv2/libsource/include/source/BufferQueue.h
+++ /dev/null
@@ -1,44 +0,0 @@
-#pragma once
-
-#include <utils/Errors.h>
-
-#include <deque>
-#include <mutex>
-
-namespace android {
-
-struct BufferQueue {
- BufferQueue(size_t count, size_t size);
- ~BufferQueue();
-
- status_t initCheck() const;
-
- size_t bufferSize() const;
-
- BufferQueue(const BufferQueue &) = delete;
- BufferQueue &operator=(const BufferQueue &) = delete;
-
- void *acquire(int64_t timeoutUs = -1ll);
- void queue(void *buffer);
-
- void *dequeueBegin(size_t *size);
- void dequeueEnd(size_t size);
-
-private:
- struct Buffer {
- void *mData;
- size_t mOffset;
- };
-
- status_t mInitCheck;
- size_t mBufferSize;
-
- std::mutex mLock;
- std::condition_variable mCondition;
-
- std::deque<void *> mEmptyBuffers;
- std::deque<Buffer> mFullBuffers;
-};
-
-} // namespace android
-
diff --git a/host/frontend/gcastv2/libsource/include/source/CameraSource.h b/host/frontend/gcastv2/libsource/include/source/CameraSource.h
deleted file mode 100644
index e4934df..0000000
--- a/host/frontend/gcastv2/libsource/include/source/CameraSource.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright 2018, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <source/StreamingSource.h>
-
-#include <media/stagefright/foundation/ABuffer.h>
-#include <media/stagefright/foundation/AMessage.h>
-
-#include <vector>
-#include <memory>
-#include <thread>
-
-namespace android {
-
-struct CameraSource : public StreamingSource {
- CameraSource();
-
- CameraSource(const CameraSource &) = delete;
- CameraSource &operator=(const CameraSource &) = delete;
-
- ~CameraSource() override;
-
- status_t initCheck() const override;
-
- sp<AMessage> getFormat() const override;
-
- status_t start() override;
- status_t stop() override;
-
- status_t pause() override;
- status_t resume() override;
-
- bool paused() const override;
-
- status_t requestIDRFrame() override;
-
-private:
- enum State {
- STOPPING,
- STOPPED,
- RUNNING,
- PAUSED
- };
-
- status_t mInitCheck;
- State mState;
-
- std::vector<sp<ABuffer>> mCSD;
-
- void *mSession;
-
- std::mutex mLock;
-
- static void onFrameData(
- void *cookie,
- ssize_t csdIndex,
- int64_t timeUs,
- const void *data,
- size_t size);
-
- void onFrameData(
- ssize_t csdIndex, int64_t timeUs, const void *data, size_t size);
-
- sp<ABuffer> prependCSD(const sp<ABuffer> &accessUnit) const;
-};
-
-} // namespace android
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef void (*CameraSessionCallback)(
- void *cookie, ssize_t csdIndex, int64_t timeUs, const void *data, size_t size);
-
-void *createCameraSession(CameraSessionCallback cb, void *cookie);
-void startCameraSession(void *session);
-void stopCameraSession(void *session);
-void pauseCameraSession(void *session);
-void resumeCameraSession(void *session);
-void destroyCameraSession(void *session);
-
-#ifdef __cplusplus
-}
-#endif
-
-
-
diff --git a/host/frontend/gcastv2/libsource/include/source/DirectRenderer_iOS.h b/host/frontend/gcastv2/libsource/include/source/DirectRenderer_iOS.h
deleted file mode 100644
index 8cb1fb1..0000000
--- a/host/frontend/gcastv2/libsource/include/source/DirectRenderer_iOS.h
+++ /dev/null
@@ -1,25 +0,0 @@
-#pragma once
-
-#include <VideoToolbox/VideoToolbox.h>
-#include <media/stagefright/foundation/AMessage.h>
-
-namespace android {
-
-struct DirectRenderer_iOS {
- DirectRenderer_iOS();
- ~DirectRenderer_iOS();
-
- void setFormat(size_t index, const sp<AMessage> &format);
- void queueAccessUnit(size_t index, const sp<ABuffer> &accessUnit);
-
- void render(CVImageBufferRef imageBuffer);
-
-private:
- CMVideoFormatDescriptionRef mVideoFormatDescription;
- VTDecompressionSessionRef mSession;
-
- DISALLOW_EVIL_CONSTRUCTORS(DirectRenderer_iOS);
-};
-
-} // namespace android
-
diff --git a/host/frontend/gcastv2/libsource/include/source/DisplayListsSource.h b/host/frontend/gcastv2/libsource/include/source/DisplayListsSource.h
deleted file mode 100644
index a51b3d0..0000000
--- a/host/frontend/gcastv2/libsource/include/source/DisplayListsSource.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#pragma once
-
-#include <source/StreamingSource.h>
-
-#include <media/stagefright/foundation/ABuffer.h>
-
-namespace android {
-
-struct DisplayListsSource : public StreamingSource {
- DisplayListsSource() = default;
-
- status_t initCheck() const override;
- sp<AMessage> getFormat() const override;
- status_t start() override;
- status_t stop() override;
- status_t requestIDRFrame() override;
-
- void inject(const void *data, size_t size);
-};
-
-} // namespace android
diff --git a/host/frontend/gcastv2/libsource/include/source/TouchSource.h b/host/frontend/gcastv2/libsource/include/source/TouchSource.h
deleted file mode 100644
index 3478bad..0000000
--- a/host/frontend/gcastv2/libsource/include/source/TouchSource.h
+++ /dev/null
@@ -1,19 +0,0 @@
-#pragma once
-
-#include <source/StreamingSource.h>
-
-namespace android {
-
-struct TouchSource : public StreamingSource {
- TouchSource() = default;
-
- status_t initCheck() const override;
- sp<AMessage> getFormat() const override;
- status_t start() override;
- status_t stop() override;
- status_t requestIDRFrame() override;
-
- void inject(bool down, int32_t x, int32_t y);
-};
-
-} // namespace android
diff --git a/host/frontend/gcastv2/libsource/include/source/VideoSink.h b/host/frontend/gcastv2/libsource/include/source/VideoSink.h
deleted file mode 100644
index ad516e6..0000000
--- a/host/frontend/gcastv2/libsource/include/source/VideoSink.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#pragma once
-
-#include <source/StreamingSink.h>
-
-#include <source/DirectRenderer_iOS.h>
-
-namespace android {
-
-struct VideoSink : public StreamingSink {
- VideoSink();
-
- void onMessageReceived(const sp<AMessage> &msg) override;
-
-private:
- std::unique_ptr<DirectRenderer_iOS> mRenderer;
- bool mFirstAccessUnit;
-};
-
-} // namespace android
-
diff --git a/host/frontend/gcastv2/webrtc/Android.bp b/host/frontend/gcastv2/webrtc/Android.bp
index 85a7568..aeab4fc 100644
--- a/host/frontend/gcastv2/webrtc/Android.bp
+++ b/host/frontend/gcastv2/webrtc/Android.bp
@@ -1,11 +1,9 @@
cc_library_static {
name: "libwebrtc",
- host_supported: true,
srcs: [
"AdbWebSocketHandler.cpp",
"DTLS.cpp",
"G711Packetizer.cpp",
-// "H264Packetizer.cpp",
"MyWebSocketHandler.cpp",
"OpusPacketizer.cpp",
"Packetizer.cpp",
@@ -19,42 +17,24 @@
"Utils.cpp",
"VP8Packetizer.cpp",
],
- target: {
- host: {
- cflags: [
- "-DTARGET_ANDROID",
- ],
- static_libs: [
- "libcuttlefish_host_config",
- "libgflags",
- "libjsoncpp",
- "libsource",
- ],
- shared_libs: [
- "libbase",
- ],
- header_libs: [
- "cuttlefish_common_headers",
- "cuttlefish_kernel_headers",
- ],
- },
- android: {
- enabled: false,
- },
- },
- arch: {
- x86: {
- enabled: false,
- }
- },
static_libs: [
"libandroidglue",
"libhttps",
"libsrtp2",
+ "libcuttlefish_host_config",
+ "libgflags",
+ "libjsoncpp",
+ "libsource",
],
shared_libs: [
"libssl",
+ "libbase",
],
+ header_libs: [
+ "cuttlefish_common_headers",
+ "cuttlefish_kernel_headers",
+ ],
+ defaults: ["cuttlefish_host_only"],
local_include_dirs: ["include"],
export_include_dirs: ["include"],
}
@@ -71,11 +51,9 @@
"libbase",
"libcrypto",
"libcuttlefish_utils",
- "libFraunhoferAAC",
"libopus",
"libssl",
"libvpx",
-// "libx264",
"libyuv",
],
static_libs: [
@@ -89,9 +67,6 @@
"libwebrtc",
],
cpp_std: "experimental",
- cflags: [
- "-DTARGET_ANDROID",
- ],
defaults: ["cuttlefish_host_only"],
}
diff --git a/host/frontend/gcastv2/webrtc/DTLS.cpp b/host/frontend/gcastv2/webrtc/DTLS.cpp
index f61a59d..ca49a08 100644
--- a/host/frontend/gcastv2/webrtc/DTLS.cpp
+++ b/host/frontend/gcastv2/webrtc/DTLS.cpp
@@ -6,17 +6,12 @@
#include <https/SSLSocket.h>
#include <https/Support.h>
#include <media/stagefright/foundation/ADebug.h>
-#include <utils/KeyStore.h>
#include <sys/socket.h>
#include <unistd.h>
#include <sstream>
-#if defined(TARGET_ANDROID_DEVICE) && defined(TARGET_ANDROID)
-#error Only one of TARGET_ANDROID or TARGET_ANDROID_DEVICE may be specified
-#endif
-
static int gDTLSInstanceIndex;
// static
@@ -242,10 +237,6 @@
<< err
<< " ("
<< SSL_state_string_long(mSSL)
-#if !defined(TARGET_ANDROID) && !defined(TARGET_ANDROID_DEVICE)
- << ", "
- << SSL_rstate_string_long(mSSL)
-#endif
<< ")";
}
}
diff --git a/host/frontend/gcastv2/webrtc/G711Packetizer.cpp b/host/frontend/gcastv2/webrtc/G711Packetizer.cpp
index 718aeb0..d514703 100644
--- a/host/frontend/gcastv2/webrtc/G711Packetizer.cpp
+++ b/host/frontend/gcastv2/webrtc/G711Packetizer.cpp
@@ -77,12 +77,6 @@
uint32_t rtpTime = ((timeUs - mStartTimeMedia) * 8) / 1000;
-#if 0
- static uint32_t lastRtpTime = 0;
- LOG(INFO) << "rtpTime = " << rtpTime << " [+" << (rtpTime - lastRtpTime) << "]";
- lastRtpTime = rtpTime;
-#endif
-
CHECK_LE(12 + size, kMaxSRTPPayloadSize);
std::vector<uint8_t> packet(12 + size);
diff --git a/host/frontend/gcastv2/webrtc/H264Packetizer.cpp b/host/frontend/gcastv2/webrtc/H264Packetizer.cpp
deleted file mode 100644
index bd79fbe..0000000
--- a/host/frontend/gcastv2/webrtc/H264Packetizer.cpp
+++ /dev/null
@@ -1,268 +0,0 @@
-#include <webrtc/H264Packetizer.h>
-
-#include "Utils.h"
-
-#include <webrtc/RTPSocketHandler.h>
-
-#include <https/SafeCallbackable.h>
-#include <media/stagefright/foundation/AMessage.h>
-#include <media/stagefright/MediaDefs.h>
-#include <media/stagefright/avc_utils.h>
-#include <media/stagefright/Utils.h>
-
-using namespace android;
-
-H264Packetizer::H264Packetizer(
- std::shared_ptr<RunLoop> runLoop,
- std::shared_ptr<FrameBufferSource> frameBufferSource)
- : mRunLoop(runLoop),
- mFrameBufferSource(frameBufferSource),
- mNumSamplesRead(0),
- mStartTimeMedia(0) {
-}
-
-void H264Packetizer::run() {
- auto weak_this = std::weak_ptr<H264Packetizer>(shared_from_this());
-
- mFrameBufferSource->setCallback(
- [weak_this](const sp<ABuffer> &accessUnit) {
- auto me = weak_this.lock();
- if (me) {
- me->mRunLoop->post(
- makeSafeCallback(
- me.get(), &H264Packetizer::onFrame, accessUnit));
- }
- });
-
- mFrameBufferSource->start();
-}
-
-void H264Packetizer::onFrame(const sp<ABuffer> &accessUnit) {
- int64_t timeUs;
- CHECK(accessUnit->meta()->findInt64("timeUs", &timeUs));
-
- auto now = std::chrono::steady_clock::now();
-
- if (mNumSamplesRead == 0) {
- mStartTimeMedia = timeUs;
- mStartTimeReal = now;
- }
-
- ++mNumSamplesRead;
-
- LOG(VERBOSE)
- << "got accessUnit of size "
- << accessUnit->size()
- << " at time "
- << timeUs;
-
- packetize(accessUnit, timeUs);
-}
-
-void H264Packetizer::packetize(const sp<ABuffer> &accessUnit, int64_t timeUs) {
- static constexpr uint8_t PT = 96;
- static constexpr uint32_t SSRC = 0xdeadbeef;
- static constexpr uint8_t STAP_A = 24;
- static constexpr uint8_t FU_A = 28;
-
- // XXX Retransmission packets add 2 bytes (for the original seqNum), should
- // probably reserve that amount in the original packets so we don't exceed
- // the MTU on retransmission.
- static const size_t kMaxSRTPPayloadSize =
- RTPSocketHandler::kMaxUDPPayloadSize - SRTP_MAX_TRAILER_LEN;
-
- const uint8_t *data = accessUnit->data();
- size_t size = accessUnit->size();
-
- uint32_t rtpTime = ((timeUs - mStartTimeMedia) * 9) / 100;
-
- std::vector<std::pair<size_t, size_t>> nalInfos;
-
- const uint8_t *nalStart;
- size_t nalSize;
- while (getNextNALUnit(&data, &size, &nalStart, &nalSize, true) == OK) {
- nalInfos.push_back(
- std::make_pair(nalStart - accessUnit->data(), nalSize));
- }
-
- size_t i = 0;
- while (i < nalInfos.size()) {
- size_t totalSize = 12 + 1;
-
- uint8_t F = 0;
- uint8_t NRI = 0;
-
- size_t j = i;
- while (j < nalInfos.size()) {
- auto [nalOffset, nalSize] = nalInfos[j];
-
- size_t fragASize = 2 + nalSize;
- if (totalSize + fragASize > kMaxSRTPPayloadSize) {
- break;
- }
-
- uint8_t header = accessUnit->data()[nalOffset];
- F |= (header & 0x80);
-
- if ((header & 0x60) > NRI) {
- NRI = header & 0x60;
- }
-
- totalSize += fragASize;
-
- ++j;
- }
-
- if (j == i) {
- // Not even a single NALU fits in a STAP-A packet, but may fit
- // inside a single-NALU packet...
-
- auto [nalOffset, nalSize] = nalInfos[i];
- if (12 + nalSize <= kMaxSRTPPayloadSize) {
- j = i + 1;
- }
- }
-
- if (j == i) {
- // Not even a single NALU fits, need an FU-A.
-
- auto [nalOffset, nalSize] = nalInfos[i];
-
- uint8_t nalHeader = accessUnit->data()[nalOffset];
-
- size_t offset = 1;
- while (offset < nalSize) {
- size_t copy = std::min(
- kMaxSRTPPayloadSize - 12 - 2, nalSize - offset);
-
- bool last = (offset + copy == nalSize);
-
- std::vector<uint8_t> packet(12 + 2 + copy);
-
- uint8_t *data = packet.data();
- data[0] = 0x80;
-
- data[1] = PT;
- if (last && i + 1 == nalInfos.size()) {
- data[1] |= 0x80; // (M)ark
- }
-
- SET_U16(&data[2], 0); // seqNum
- SET_U32(&data[4], rtpTime);
- SET_U32(&data[8], SSRC);
-
- data[12] = (nalHeader & 0xe0) | FU_A;
-
- data[13] = (nalHeader & 0x1f);
-
- if (offset == 1) {
- CHECK_LT(offset + copy, nalSize);
- data[13] |= 0x80; // (S)tart
- } else if (last) {
- CHECK_GT(offset, 1u);
- data[13] |= 0x40; // (E)nd
- }
-
- memcpy(&data[14], accessUnit->data() + nalOffset + offset, copy);
-
- offset += copy;
-
- LOG(VERBOSE)
- << "Sending FU-A w/ indicator "
- << StringPrintf("0x%02x", data[12])
- << ", header "
- << StringPrintf("0x%02x", data[13]);
-
- queueRTPDatagram(&packet);
- }
-
- ++i;
- continue;
- }
-
- if (j == i + 1) {
- // Only a single NALU fits.
-
- auto [nalOffset, nalSize] = nalInfos[i];
-
- std::vector<uint8_t> packet(12 + nalSize);
-
- uint8_t *data = packet.data();
- data[0] = 0x80;
-
- data[1] = PT;
- if (i + 1 == nalInfos.size()) {
- data[1] |= 0x80; // (M)arker
- }
-
- SET_U16(&data[2], 0); // seqNum
- SET_U32(&data[4], rtpTime);
- SET_U32(&data[8], SSRC);
-
- memcpy(data + 12, accessUnit->data() + nalOffset, nalSize);
-
- LOG(VERBOSE) << "Sending single NALU of size " << nalSize;
-
- queueRTPDatagram(&packet);
-
- ++i;
- continue;
- }
-
- // STAP-A
-
- std::vector<uint8_t> packet(totalSize);
-
- uint8_t *data = packet.data();
- data[0] = 0x80;
-
- data[1] = PT;
- if (j == nalInfos.size()) {
- data[1] |= 0x80; // (M)arker
- }
-
- SET_U16(&data[2], 0); // seqNum
- SET_U32(&data[4], rtpTime);
- SET_U32(&data[8], SSRC);
-
- data[12] = F | NRI | STAP_A;
-
- size_t offset = 13;
- while (i < j) {
- auto [nalOffset, nalSize] = nalInfos[i];
-
- SET_U16(&data[offset], nalSize);
- memcpy(&data[offset + 2], accessUnit->data() + nalOffset, nalSize);
-
- offset += 2 + nalSize;
-
- ++i;
- }
-
- CHECK_EQ(offset, totalSize);
-
- LOG(VERBOSE) << "Sending STAP-A of size " << totalSize;
-
- queueRTPDatagram(&packet);
- }
-}
-
-uint32_t H264Packetizer::rtpNow() const {
- if (mNumSamplesRead == 0) {
- return 0;
- }
-
- auto now = std::chrono::steady_clock::now();
- auto timeSinceStart = now - mStartTimeReal;
-
- auto us_since_start =
- std::chrono::duration_cast<std::chrono::microseconds>(
- timeSinceStart).count();
-
- return (us_since_start * 9) / 100;
-}
-
-android::status_t H264Packetizer::requestIDRFrame() {
- return mFrameBufferSource->requestIDRFrame();
-}
-
diff --git a/host/frontend/gcastv2/webrtc/OpusPacketizer.cpp b/host/frontend/gcastv2/webrtc/OpusPacketizer.cpp
index 5331ec1..b285c1d 100644
--- a/host/frontend/gcastv2/webrtc/OpusPacketizer.cpp
+++ b/host/frontend/gcastv2/webrtc/OpusPacketizer.cpp
@@ -75,12 +75,6 @@
uint32_t rtpTime = ((timeUs - mStartTimeMedia) * 48) / 1000;
-#if 0
- static uint32_t lastRtpTime = 0;
- LOG(INFO) << "rtpTime = " << rtpTime << " [+" << (rtpTime - lastRtpTime) << "]";
- lastRtpTime = rtpTime;
-#endif
-
CHECK_LE(12 + size, kMaxSRTPPayloadSize);
std::vector<uint8_t> packet(12 + size);
diff --git a/host/frontend/gcastv2/webrtc/RTPSender.cpp b/host/frontend/gcastv2/webrtc/RTPSender.cpp
index 36ef041..ca4a698 100644
--- a/host/frontend/gcastv2/webrtc/RTPSender.cpp
+++ b/host/frontend/gcastv2/webrtc/RTPSender.cpp
@@ -106,11 +106,6 @@
static constexpr uint8_t PSFB = 206;
static constexpr uint8_t XR = 207; // RFC 3611
-#if 0
- LOG(INFO) << "RTPSender::processRTCP";
- android::hexdump(data, size);
-#endif
-
unsigned PT = data[1];
switch (PT) {
diff --git a/host/frontend/gcastv2/webrtc/RTPSocketHandler.cpp b/host/frontend/gcastv2/webrtc/RTPSocketHandler.cpp
index 42b761a..dc31c49 100644
--- a/host/frontend/gcastv2/webrtc/RTPSocketHandler.cpp
+++ b/host/frontend/gcastv2/webrtc/RTPSocketHandler.cpp
@@ -16,15 +16,9 @@
#include <iostream>
#include <set>
-#if defined(TARGET_ANDROID)
#include <gflags/gflags.h>
DECLARE_string(public_ip);
-#endif
-
-#ifdef TARGET_ANDROID_DEVICE
-#include <ifaddrs.h>
-#endif
static socklen_t getSockAddrLen(const sockaddr_storage &addr) {
switch (addr.ss_family) {
@@ -114,70 +108,6 @@
}
}
-#ifdef TARGET_ANDROID_DEVICE
-static std::string getSockAddrHostName(const sockaddr *addr) {
- char buffer[256];
-
- switch (addr->sa_family) {
- case AF_INET:
- {
- auto addrV4 = reinterpret_cast<const sockaddr_in *>(addr);
-
- auto out = inet_ntop(
- AF_INET, &addrV4->sin_addr, buffer, sizeof(buffer));
-
- CHECK(out);
- break;
- }
-
- case AF_INET6:
- {
- auto addrV6 = reinterpret_cast<const sockaddr_in6 *>(addr);
-
- auto out = inet_ntop(
- AF_INET6, &addrV6->sin6_addr, buffer, sizeof(buffer));
-
- CHECK(out);
- break;
- }
-
- default:
- CHECK(!"Should not be here.");
- }
-
- return buffer;
-}
-
-static std::string getWifiInterfaceAddress(int family) {
- ifaddrs *tmp;
- if (getifaddrs(&tmp)) {
- LOG(ERROR)
- << "getifaddrs return error "
- << errno
- << " ("
- << strerror(errno)
- << ")";
-
- return "127.0.0.1";
- }
-
- std::unique_ptr<ifaddrs, std::function<void(ifaddrs *)>> ifaces(
- tmp, freeifaddrs);
-
- for (tmp = ifaces.get(); tmp; tmp = tmp->ifa_next) {
- if (strcmp(tmp->ifa_name, "wlan0")
- || tmp->ifa_addr->sa_family != family) {
- continue;
- }
-
- return getSockAddrHostName(tmp->ifa_addr);
- }
-
- LOG(WARNING) << "getWifiInterfaceAddress did not find a 'wlan0' interface.";
- return "127.0.0.1";
-}
-#endif
-
uint16_t RTPSocketHandler::getLocalPort() const {
return mLocalPort;
}
@@ -187,54 +117,7 @@
}
std::string RTPSocketHandler::getLocalIPString() const {
-#if 0
- sockaddr_storage addr;
- socklen_t addrLen = sizeof(addr);
-
- int res = getsockname(
- mSocket->fd(), reinterpret_cast<sockaddr *>(&addr), &addrLen);
-
- CHECK(!res);
-
- char buffer[256];
-
- switch (addr.ss_family) {
- case AF_INET:
- {
- sockaddr_in addrV4;
- memcpy(&addrV4, &addr, sizeof(addrV4));
-
- auto out = inet_ntop(AF_INET, &addrV4.sin_addr, buffer, sizeof(buffer));
- CHECK(out);
-
- return "100.122.57.45"; // XXX
- break;
- }
-
- case AF_INET6:
- {
- sockaddr_in6 addrV6;
- memcpy(&addrV6, &addr, sizeof(addrV6));
-
- auto out = inet_ntop(AF_INET6, &addrV6.sin6_addr, buffer, sizeof(buffer));
- CHECK(out);
-
- return "2620::1000:1610:b5d5:7493:a307:ca94"; // XXX
- break;
- }
-
- default:
- CHECK(!"Should not be here.");
- }
-
- return std::string(buffer);
-#elif defined(TARGET_ANDROID)
return FLAGS_public_ip;
-#elif defined(TARGET_ANDROID_DEVICE)
- return getWifiInterfaceAddress(AF_INET);
-#else
- return "127.0.0.1";
-#endif
}
void RTPSocketHandler::run() {
@@ -252,12 +135,6 @@
auto n = mSocket->recvfrom(
data, buffer.size(), reinterpret_cast<sockaddr *>(&addr), &addrLen);
-#if 0
- std::cout << "========================================" << std::endl;
-
- hexdump(data, n);
-#endif
-
STUNMessage msg(data, n);
if (!msg.isValid()) {
if (mDTLSConnected) {
@@ -608,11 +485,6 @@
}
int RTPSocketHandler::onSRTPReceive(uint8_t *data, size_t size) {
-#if 0
- LOG(INFO) << "onSRTPReceive";
- hexdump(data, size);
-#endif
-
if (size < 2) {
return -EINVAL;
}
@@ -624,11 +496,6 @@
auto outSize = mDTLS->unprotect(data, size, false /* isRTP */);
-#if 0
- LOG(INFO) << "After srtp_unprotect_rtcp" << ":";
- hexdump(data, outSize);
-#endif
-
auto err = mRTPSender->injectRTCP(data, outSize);
if (err) {
LOG(WARNING) << "RTPSender::injectRTCP returned " << err;
diff --git a/host/frontend/gcastv2/webrtc/STUNMessage.cpp b/host/frontend/gcastv2/webrtc/STUNMessage.cpp
index 22bfb2a..aeb5b7a 100644
--- a/host/frontend/gcastv2/webrtc/STUNMessage.cpp
+++ b/host/frontend/gcastv2/webrtc/STUNMessage.cpp
@@ -12,11 +12,7 @@
#include <iostream>
#include <unordered_map>
-#if defined(TARGET_ANDROID) || defined(TARGET_ANDROID_DEVICE)
#include <openssl/hmac.h>
-#else
-#include <Security/Security.h>
-#endif
static constexpr uint8_t kMagicCookie[4] = { 0x21, 0x12, 0xa4, 0x42 };
@@ -84,7 +80,6 @@
mData[2] = (truncatedLength >> 8);
mData[3] = (truncatedLength & 0xff);
-#if defined(TARGET_ANDROID) || defined(TARGET_ANDROID_DEVICE)
uint8_t digest[20];
unsigned int digestLen = sizeof(digest);
@@ -98,53 +93,6 @@
CHECK_EQ(digestLen, 20);
addAttribute(0x0008 /* MESSAGE-INTEGRITY */, digest, digestLen);
-#else
- CFErrorRef err;
- auto digest = SecDigestTransformCreate(
- kSecDigestHMACSHA1, 20 /* digestLength */, &err);
-
- CHECK(digest);
-
- auto input = CFDataCreateWithBytesNoCopy(
- kCFAllocatorDefault, mData.data(), offset, kCFAllocatorNull);
-
- auto success = SecTransformSetAttribute(
- digest, kSecTransformInputAttributeName, input, &err);
-
- CFRelease(input);
- input = nullptr;
-
- CHECK(success);
-
- auto key = CFDataCreateWithBytesNoCopy(
- kCFAllocatorDefault,
- reinterpret_cast<const UInt8 *>(password.data()),
- password.size(),
- kCFAllocatorNull);
-
- success = SecTransformSetAttribute(
- digest, kSecDigestHMACKeyAttribute, key, &err);
-
- CFRelease(key);
- key = nullptr;
-
- CHECK(success);
-
- auto output = SecTransformExecute(digest, &err);
- CHECK(output);
-
- auto outputAsData = static_cast<CFDataRef>(output);
- CHECK_EQ(CFDataGetLength(outputAsData), 20);
-
- addAttribute(
- 0x0008 /* MESSAGE-INTEGRITY */, CFDataGetBytePtr(outputAsData), 20);
-
- CFRelease(output);
- output = nullptr;
-
- CFRelease(digest);
- digest = nullptr;
-#endif
mAddedMessageIntegrity = true;
}
@@ -324,7 +272,6 @@
copy[2] = (truncatedLength >> 8);
copy[3] = (truncatedLength & 0xff);
-#if defined(TARGET_ANDROID) || defined(TARGET_ANDROID_DEVICE)
uint8_t digest[20];
unsigned int digestLen = sizeof(digest);
@@ -344,54 +291,6 @@
digestLen);
return success;
-#else
- CFErrorRef err;
- auto digest = SecDigestTransformCreate(
- kSecDigestHMACSHA1, 20 /* digestLength */, &err);
-
- CHECK(digest);
-
- auto input = CFDataCreateWithBytesNoCopy(
- kCFAllocatorDefault, copy.data(), copy.size(), kCFAllocatorNull);
-
- auto success = SecTransformSetAttribute(
- digest, kSecTransformInputAttributeName, input, &err);
-
- CFRelease(input);
- input = nullptr;
-
- CHECK(success);
-
- auto key = CFDataCreateWithBytesNoCopy(
- kCFAllocatorDefault,
- reinterpret_cast<const UInt8 *>(password.data()),
- password.size(),
- kCFAllocatorNull);
-
- success = SecTransformSetAttribute(
- digest, kSecDigestHMACKeyAttribute, key, &err);
-
- CFRelease(key);
- key = nullptr;
-
- CHECK(success);
-
- auto output = SecTransformExecute(digest, &err);
- CHECK(output);
-
- success = !memcmp(
- CFDataGetBytePtr(static_cast<CFDataRef>(output)),
- &mData[offset + 4],
- 20);
-
- CFRelease(output);
- output = nullptr;
-
- CFRelease(digest);
- digest = nullptr;
-
- return success;
-#endif
}
void STUNMessage::addFingerprint() {
diff --git a/host/frontend/gcastv2/webrtc/ServerState.cpp b/host/frontend/gcastv2/webrtc/ServerState.cpp
index 1900471..bf53678 100644
--- a/host/frontend/gcastv2/webrtc/ServerState.cpp
+++ b/host/frontend/gcastv2/webrtc/ServerState.cpp
@@ -1,10 +1,8 @@
#include <webrtc/ServerState.h>
-#include <webrtc/H264Packetizer.h>
#include <webrtc/OpusPacketizer.h>
#include <webrtc/VP8Packetizer.h>
-#ifdef TARGET_ANDROID
#include <source/AudioSource.h>
#include <source/TouchSink.h>
#include <source/FrameBufferSource.h>
@@ -16,32 +14,19 @@
DECLARE_int32(touch_fd);
DECLARE_int32(frame_server_fd);
DECLARE_bool(write_virtio_input);
-#endif
-
-#ifdef TARGET_ANDROID_DEVICE
-#include <source/DeviceFrameBufferSource.h>
-#include <source/DeviceTouchSink.h>
-#endif
#define ENABLE_H264 0
ServerState::ServerState(
-#ifdef TARGET_ANDROID_DEVICE
- const sp<MyContext> &context,
-#endif
std::shared_ptr<RunLoop> runLoop, VideoFormat videoFormat)
:
-#ifdef TARGET_ANDROID_DEVICE
- mContext(context),
-#endif
- mRunLoop(runLoop),
+ mRunLoop(runLoop),
mVideoFormat(videoFormat) {
// This is the list of ports we currently instruct the firewall to open.
mAvailablePorts.insert(
{ 15550, 15551, 15552, 15553, 15554, 15555, 15556, 15557 });
-#ifdef TARGET_ANDROID
auto config = vsoc::CuttlefishConfig::Get();
mHostToGuestComms = std::make_shared<HostToGuestComms>(
@@ -112,9 +97,6 @@
screenParams[2] = config->dpi();
screenParams[3] = config->refresh_rate_hz();
- mFrameBufferComms->send(
- screenParams, sizeof(screenParams), false /* addFraming */);
-
static_cast<android::FrameBufferSource *>(
mFrameBufferSource.get())->setScreenParams(screenParams);
@@ -146,25 +128,6 @@
touchSink->start();
mTouchSink = touchSink;
-#else
- mLooper = new ALooper;
- mLooper->start();
-
- mFrameBufferSource = std::make_shared<android::DeviceFrameBufferSource>(
- mContext,
- mLooper,
- android::DeviceFrameBufferSource::Type::VP8);
-
- mAudioLooper = new ALooper;
- mAudioLooper->start();
-
- mAudioSource = std::make_shared<android::DeviceFrameBufferSource>(
- mContext,
- mAudioLooper,
- android::DeviceFrameBufferSource::Type::OPUS);
-
- mTouchSink = std::make_shared<android::DeviceTouchSink>();
-#endif
}
std::shared_ptr<Packetizer> ServerState::getVideoPacketizer() {
@@ -248,7 +211,6 @@
return mTouchSink;
}
-#ifdef TARGET_ANDROID
void ServerState::changeResolution(
int32_t width, int32_t height, int32_t densityDpi) {
LOG(INFO)
@@ -317,5 +279,3 @@
mHostToGuestComms->send(packet.get(), totalSize);
}
-
-#endif // defined(TARGET_ANDROID)
diff --git a/host/frontend/gcastv2/webrtc/Utils.cpp b/host/frontend/gcastv2/webrtc/Utils.cpp
index 917c313..f2d7acb 100644
--- a/host/frontend/gcastv2/webrtc/Utils.cpp
+++ b/host/frontend/gcastv2/webrtc/Utils.cpp
@@ -40,39 +40,6 @@
dst[3] = x & 0xff;
}
-#if 0
-static uint32_t crc32ForByte(uint32_t x) {
- for (size_t i = 0; i < 8; ++i) {
- if (x & 1) {
- x = 0xedb88320 ^ (x >> 1);
- } else {
- x >>= 1;
- }
- }
-
- return x;
-}
-
-uint32_t computeCrc32(const void *_data, size_t size) {
- static uint32_t kTable[256];
- if (!kTable[0]) {
- for (size_t i = 0; i < 256; ++i) {
- kTable[i] = crc32ForByte(i);
- }
- }
-
- const uint8_t *data = static_cast<const uint8_t *>(_data);
-
- uint32_t crc32 = 0xffffffff;
- for (size_t i = 0; i < size; ++i) {
- uint8_t x = data[i];
-
- crc32 = (crc32 >> 8) ^ kTable[(crc32 & 0xff) ^ x];
- }
-
- return ~crc32;
-}
-#else
static const uint32_t crc32_tab[] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
@@ -126,15 +93,8 @@
for (size_t i = 0; i < size; ++i) {
uint32_t lkp = crc32_tab[(crc ^ data[i]) & 0xFF];
-#if 0
- bool wlm2009_stupid_crc32_typo = false;
- if (lkp == 0x8bbeb8ea && wlm2009_stupid_crc32_typo) {
- lkp = 0x8bbe8ea;
- }
-#endif
crc = lkp ^ (crc >> 8);
}
return crc ^ 0xffffffff;
}
-#endif
diff --git a/host/frontend/gcastv2/webrtc/VP8Packetizer.cpp b/host/frontend/gcastv2/webrtc/VP8Packetizer.cpp
index d5cae1c..9a34da0 100644
--- a/host/frontend/gcastv2/webrtc/VP8Packetizer.cpp
+++ b/host/frontend/gcastv2/webrtc/VP8Packetizer.cpp
@@ -113,11 +113,6 @@
CHECK_EQ(dstOffset, packetSize);
-#if 0
- LOG(INFO) << "Sending packet of size " << packetSize;
- hexdump(dst, std::min(128ul, packetSize));
-#endif
-
srcOffset += copy;
queueRTPDatagram(&packet);
diff --git a/host/frontend/gcastv2/webrtc/include/webrtc/H264Packetizer.h b/host/frontend/gcastv2/webrtc/include/webrtc/H264Packetizer.h
deleted file mode 100644
index ea70990..0000000
--- a/host/frontend/gcastv2/webrtc/include/webrtc/H264Packetizer.h
+++ /dev/null
@@ -1,42 +0,0 @@
-#pragma once
-
-#include "Packetizer.h"
-
-#include <https/RunLoop.h>
-#include <media/stagefright/foundation/ABuffer.h>
-#include <media/stagefright/NuMediaExtractor.h>
-
-#include <memory>
-
-#include <source/StreamingSource.h>
-
-struct H264Packetizer
- : public Packetizer, public std::enable_shared_from_this<H264Packetizer> {
- using StreamingSource = android::StreamingSource;
-
- explicit H264Packetizer(
- std::shared_ptr<RunLoop> runLoop,
- std::shared_ptr<StreamingSource> frameBufferSource);
-
- void run() override;
- uint32_t rtpNow() const override;
- android::status_t requestIDRFrame() override;
-
-private:
- using ABuffer = android::ABuffer;
- template<class T> using sp = android::sp<T>;
-
- std::shared_ptr<RunLoop> mRunLoop;
-
- std::shared_ptr<StreamingSource> mFrameBufferSource;
-
- size_t mNumSamplesRead;
-
- std::chrono::time_point<std::chrono::steady_clock> mStartTimeReal;
- int64_t mStartTimeMedia;
-
- void onFrame(const sp<ABuffer> &accessUnit);
-
- void packetize(const sp<ABuffer> &accessUnit, int64_t timeUs);
-};
-
diff --git a/host/frontend/gcastv2/webrtc/include/webrtc/ServerState.h b/host/frontend/gcastv2/webrtc/include/webrtc/ServerState.h
index dfeb66e..ea7811e 100644
--- a/host/frontend/gcastv2/webrtc/include/webrtc/ServerState.h
+++ b/host/frontend/gcastv2/webrtc/include/webrtc/ServerState.h
@@ -4,14 +4,7 @@
#include <https/RunLoop.h>
-#ifdef TARGET_ANDROID
#include <source/HostToGuestComms.h>
-#elif defined(TARGET_ANDROID_DEVICE)
-#include <media/stagefright/foundation/ALooper.h>
-#include <platform/MyContext.h>
-#else
-#error "Either TARGET_ANDROID or TARGET_ANDROID_DEVICE must be defined."
-#endif
#include <source/StreamingSink.h>
#include <source/StreamingSource.h>
@@ -23,19 +16,11 @@
struct ServerState {
using StreamingSink = android::StreamingSink;
-#ifdef TARGET_ANDROID_DEVICE
- template<class T> using sp = android::sp<T>;
- using MyContext = android::MyContext;
-#endif
-
enum class VideoFormat {
H264,
VP8,
};
explicit ServerState(
-#ifdef TARGET_ANDROID_DEVICE
- const sp<MyContext> &context,
-#endif
std::shared_ptr<RunLoop> runLoop,
VideoFormat videoFormat);
@@ -54,10 +39,6 @@
private:
using StreamingSource = android::StreamingSource;
-#ifdef TARGET_ANDROID_DEVICE
- sp<MyContext> mContext;
-#endif
-
std::shared_ptr<RunLoop> mRunLoop;
VideoFormat mVideoFormat;
@@ -69,14 +50,9 @@
std::shared_ptr<StreamingSource> mAudioSource;
-#ifdef TARGET_ANDROID
std::shared_ptr<HostToGuestComms> mHostToGuestComms;
std::shared_ptr<HostToGuestComms> mFrameBufferComms;
std::shared_ptr<HostToGuestComms> mAudioComms;
-#else
- using ALooper = android::ALooper;
- sp<ALooper> mLooper, mAudioLooper;
-#endif
std::shared_ptr<StreamingSink> mTouchSink;
@@ -85,7 +61,5 @@
std::mutex mPortLock;
std::set<uint16_t> mAvailablePorts;
-#ifdef TARGET_ANDROID
void changeResolution(int32_t width, int32_t height, int32_t densityDpi);
-#endif
};
diff --git a/host/frontend/gcastv2/webrtc/webRTC.cpp b/host/frontend/gcastv2/webrtc/webRTC.cpp
index 6d7fce8..d1da895 100644
--- a/host/frontend/gcastv2/webrtc/webRTC.cpp
+++ b/host/frontend/gcastv2/webrtc/webRTC.cpp
@@ -17,7 +17,6 @@
#include <iostream>
#include <unordered_map>
-#if defined(TARGET_ANDROID)
#include <gflags/gflags.h>
DEFINE_string(
@@ -39,15 +38,9 @@
DEFINE_bool(write_virtio_input, false, "Whether to send input events in virtio format.");
DEFINE_string(adb, "", "Interface:port of local adb service.");
-#endif
int main(int argc, char **argv) {
-#if defined(TARGET_ANDROID)
::gflags::ParseCommandLineFlags(&argc, &argv, true);
-#else
- (void)argc;
- (void)argv;
-#endif
SSLSocket::Init();
DTLS::Init();
@@ -57,7 +50,6 @@
auto state = std::make_shared<ServerState>(
runLoop, ServerState::VideoFormat::VP8);
-#if 1
auto port = 8443; // Change to 8080 to use plain http instead of https.
auto httpd = std::make_shared<HTTPServer>(
@@ -91,7 +83,6 @@
return std::make_pair(0 /* OK */, handler);
});
-#if defined(TARGET_ANDROID)
if (!FLAGS_adb.empty()) {
httpd->addWebSocketHandlerFactory(
"/control_adb",
@@ -104,60 +95,8 @@
return std::make_pair(0 /* OK */, handler);
});
}
-#endif
httpd->run();
-#else
- uint16_t receiverPort = 63843;
- std::string receiverUFrag = "N1NB";
- std::string receiverPassword = "deadbeef";
-
- uint16_t senderPort = 63844;
- std::string senderUFrag = "ABCD";
- std::string senderPassword = "wooops";
-
- auto sender = std::make_shared<RTPSocketHandler>(
- runLoop,
- RTPSocketHandler::Mode::CONTROLLER,
- AF_INET,
- senderPort,
- false /* isChrome */);
-
- sender->addSession(
- senderUFrag,
- senderPassword,
- receiverUFrag,
- receiverPassword);
-
- sockaddr_in addr;
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
- addr.sin_port = htons(senderPort);
-
- sockaddr_storage senderAddr;
- memcpy(&senderAddr, &addr, sizeof(addr));
-
- auto receiver = std::make_shared<RTPSocketHandler>(
- runLoop,
- RTPSocketHandler::Mode::CONTROLLEE,
- AF_INET,
- receiverPort,
- false /* isChrome */);
-
- receiver->addSession(
- receiverUFrag,
- receiverPassword,
- senderUFrag,
- senderPassword,
- senderAddr);
-
- sender->run();
- receiver->run();
-
- receiver->kick();
-#endif
-
runLoop->run();
return 0;
diff --git a/host_package.mk b/host_package.mk
index 7301b75..2aa5c93 100644
--- a/host_package.mk
+++ b/host_package.mk
@@ -80,7 +80,6 @@
libssl-host.so \
libopus.so \
libyuv.so \
- libFraunhoferAAC.so \
libjpeg.so \