Merge changes from topic "124962433" into qt-dev
* changes:
codec2: Derive video encoder components from SimpleInterface
codec2: Add support to derive from base class for audio decoders
codec2: Add support to derive from base class for audio encoders
diff --git a/camera/ndk/ndk_vendor/impl/ACameraDevice.cpp b/camera/ndk/ndk_vendor/impl/ACameraDevice.cpp
index 1fdff40..529c167 100644
--- a/camera/ndk/ndk_vendor/impl/ACameraDevice.cpp
+++ b/camera/ndk/ndk_vendor/impl/ACameraDevice.cpp
@@ -259,15 +259,27 @@
}
}
+static void addMetadataToPhysicalCameraSettings(const CameraMetadata *metadata,
+ const std::string &cameraId, PhysicalCameraSettings *physicalCameraSettings) {
+ CameraMetadata metadataCopy = *metadata;
+ camera_metadata_t *camera_metadata = metadataCopy.release();
+ HCameraMetadata hCameraMetadata;
+ utils::convertToHidl(camera_metadata, &hCameraMetadata, /*shouldOwn*/ true);
+ physicalCameraSettings->settings.metadata(std::move(hCameraMetadata));
+ physicalCameraSettings->id = cameraId;
+}
+
void CameraDevice::addRequestSettingsMetadata(ACaptureRequest *aCaptureRequest,
sp<CaptureRequest> &req) {
- CameraMetadata metadataCopy = aCaptureRequest->settings->getInternalData();
- const camera_metadata_t *camera_metadata = metadataCopy.getAndLock();
- HCameraMetadata hCameraMetadata;
- utils::convertToHidl(camera_metadata, &hCameraMetadata);
- metadataCopy.unlock(camera_metadata);
- req->mPhysicalCameraSettings.resize(1);
- req->mPhysicalCameraSettings[0].settings.metadata(std::move(hCameraMetadata));
+ req->mPhysicalCameraSettings.resize(1 + aCaptureRequest->physicalSettings.size());
+ addMetadataToPhysicalCameraSettings(&(aCaptureRequest->settings->getInternalData()), getId(),
+ &(req->mPhysicalCameraSettings[0]));
+ size_t i = 1;
+ for (auto &physicalSetting : aCaptureRequest->physicalSettings) {
+ addMetadataToPhysicalCameraSettings(&(physicalSetting.second->getInternalData()),
+ physicalSetting.first, &(req->mPhysicalCameraSettings[i]));
+ i++;
+ }
}
camera_status_t CameraDevice::updateOutputConfigurationLocked(ACaptureSessionOutput *output) {
@@ -398,10 +410,9 @@
cameraSettings.id = id;
// TODO: Do we really need to copy the metadata here ?
CameraMetadata metadataCopy = metadata->getInternalData();
- const camera_metadata_t *cameraMetadata = metadataCopy.getAndLock();
+ camera_metadata_t *cameraMetadata = metadataCopy.release();
HCameraMetadata hCameraMetadata;
- utils::convertToHidl(cameraMetadata, &hCameraMetadata);
- metadataCopy.unlock(cameraMetadata);
+ utils::convertToHidl(cameraMetadata, &hCameraMetadata, true);
if (metadata != nullptr) {
if (hCameraMetadata.data() != nullptr &&
mCaptureRequestMetadataQueue != nullptr &&
@@ -426,11 +437,12 @@
const std::string& id = req->mPhysicalCameraSettings[i].id;
CameraMetadata clone;
utils::convertFromHidlCloned(req->mPhysicalCameraSettings[i].settings.metadata(), &clone);
+ camera_metadata_t *clonep = clone.release();
if (id == deviceId) {
- pRequest->settings = new ACameraMetadata(clone.release(), ACameraMetadata::ACM_REQUEST);
+ pRequest->settings = new ACameraMetadata(clonep, ACameraMetadata::ACM_REQUEST);
} else {
pRequest->physicalSettings[req->mPhysicalCameraSettings[i].id] =
- new ACameraMetadata(clone.release(), ACameraMetadata::ACM_REQUEST);
+ new ACameraMetadata(clonep, ACameraMetadata::ACM_REQUEST);
}
}
pRequest->targets = new ACameraOutputTargets();
diff --git a/camera/ndk/ndk_vendor/impl/utils.cpp b/camera/ndk/ndk_vendor/impl/utils.cpp
index 5d2d47c..e4fb204 100644
--- a/camera/ndk/ndk_vendor/impl/utils.cpp
+++ b/camera/ndk/ndk_vendor/impl/utils.cpp
@@ -64,13 +64,14 @@
return true;
}
-// Note: existing data in dst will be gone. Caller still owns the memory of src
-void convertToHidl(const camera_metadata_t *src, HCameraMetadata* dst) {
+// Note: existing data in dst will be gone. dst owns memory if shouldOwn is set
+// to true.
+void convertToHidl(const camera_metadata_t *src, HCameraMetadata* dst, bool shouldOwn) {
if (src == nullptr) {
return;
}
size_t size = get_camera_metadata_size(src);
- dst->setToExternal((uint8_t *) src, size);
+ dst->setToExternal((uint8_t *) src, size, shouldOwn);
return;
}
diff --git a/camera/ndk/ndk_vendor/impl/utils.h b/camera/ndk/ndk_vendor/impl/utils.h
index a03c7bc..f389f03 100644
--- a/camera/ndk/ndk_vendor/impl/utils.h
+++ b/camera/ndk/ndk_vendor/impl/utils.h
@@ -168,8 +168,8 @@
bool convertFromHidlCloned(const HCameraMetadata &metadata, CameraMetadata *rawMetadata);
-// Note: existing data in dst will be gone. Caller still owns the memory of src
-void convertToHidl(const camera_metadata_t *src, HCameraMetadata* dst);
+// Note: existing data in dst will be gone.
+void convertToHidl(const camera_metadata_t *src, HCameraMetadata* dst, bool shouldOwn = false);
TemplateId convertToHidl(ACameraDevice_request_template templateId);
diff --git a/media/codec2/vndk/C2Store.cpp b/media/codec2/vndk/C2Store.cpp
index f5dc838..10c4dcc 100644
--- a/media/codec2/vndk/C2Store.cpp
+++ b/media/codec2/vndk/C2Store.cpp
@@ -26,7 +26,6 @@
#include <C2Config.h>
#include <C2PlatformStorePluginLoader.h>
#include <C2PlatformSupport.h>
-#include <media/stagefright/foundation/ADebug.h>
#include <util/C2InterfaceHelper.h>
#include <dlfcn.h>
@@ -662,36 +661,30 @@
ALOGV("in %s", __func__);
ALOGV("loading dll");
mLibHandle = dlopen(libPath.c_str(), RTLD_NOW|RTLD_NODELETE);
- if (mLibHandle == nullptr) {
- LOG_ALWAYS_FATAL_IN_CHILD_PROC("could not dlopen %s: %s", libPath.c_str(), dlerror());
- mInit = C2_CORRUPTED;
- return mInit;
- }
+ LOG_ALWAYS_FATAL_IF(mLibHandle == nullptr,
+ "could not dlopen %s: %s", libPath.c_str(), dlerror());
createFactory =
(C2ComponentFactory::CreateCodec2FactoryFunc)dlsym(mLibHandle, "CreateCodec2Factory");
- if (createFactory == nullptr) {
- LOG_ALWAYS_FATAL_IN_CHILD_PROC("createFactory is null in %s", libPath.c_str());
- mInit = C2_CORRUPTED;
- return mInit;
- }
+ LOG_ALWAYS_FATAL_IF(createFactory == nullptr,
+ "createFactory is null in %s", libPath.c_str());
destroyFactory =
(C2ComponentFactory::DestroyCodec2FactoryFunc)dlsym(mLibHandle, "DestroyCodec2Factory");
- if (destroyFactory == nullptr) {
- LOG_ALWAYS_FATAL_IN_CHILD_PROC("destroyFactory is null in %s", libPath.c_str());
- mInit = C2_CORRUPTED;
- return mInit;
- }
+ LOG_ALWAYS_FATAL_IF(destroyFactory == nullptr,
+ "destroyFactory is null in %s", libPath.c_str());
mComponentFactory = createFactory();
if (mComponentFactory == nullptr) {
ALOGD("could not create factory in %s", libPath.c_str());
mInit = C2_NO_MEMORY;
- return mInit;
+ } else {
+ mInit = C2_OK;
}
- mInit = C2_OK;
+ if (mInit != C2_OK) {
+ return mInit;
+ }
std::shared_ptr<C2ComponentInterface> intf;
c2_status_t res = createInterface(0, &intf);
diff --git a/media/extractors/mp4/ItemTable.cpp b/media/extractors/mp4/ItemTable.cpp
index d56abaa..8c8e6d1 100644
--- a/media/extractors/mp4/ItemTable.cpp
+++ b/media/extractors/mp4/ItemTable.cpp
@@ -426,10 +426,8 @@
}
ALOGV("extent_count %d", extent_count);
- if (extent_count > 1 && (offset_size == 0 || length_size == 0)) {
- // if the item is dividec into more than one extents, offset and
- // length must be present.
- return ERROR_MALFORMED;
+ if (extent_count > 1) {
+ return ERROR_UNSUPPORTED;
}
offset += 2;
diff --git a/media/extractors/mp4/MPEG4Extractor.cpp b/media/extractors/mp4/MPEG4Extractor.cpp
index e1bfb62..b4fd811 100755
--- a/media/extractors/mp4/MPEG4Extractor.cpp
+++ b/media/extractors/mp4/MPEG4Extractor.cpp
@@ -45,6 +45,7 @@
#include <media/stagefright/foundation/ColorUtils.h>
#include <media/stagefright/foundation/avc_utils.h>
#include <media/stagefright/foundation/hexdump.h>
+#include <media/stagefright/foundation/OpusHeader.h>
#include <media/stagefright/MediaBufferGroup.h>
#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/MetaDataBase.h>
@@ -1735,15 +1736,21 @@
AMediaFormat_setInt32(mLastTrack->meta, AMEDIAFORMAT_KEY_SAMPLE_RATE, sample_rate);
if (chunk_type == FOURCC("Opus")) {
- uint8_t opusInfo[19];
+ uint8_t opusInfo[AOPUS_OPUSHEAD_MAXSIZE];
data_offset += sizeof(buffer);
+ size_t opusInfoSize = chunk_data_size - sizeof(buffer);
+
+ if (opusInfoSize < AOPUS_OPUSHEAD_MINSIZE ||
+ opusInfoSize > AOPUS_OPUSHEAD_MAXSIZE) {
+ return ERROR_MALFORMED;
+ }
// Read Opus Header
if (mDataSource->readAt(
- data_offset, opusInfo, sizeof(opusInfo)) < (ssize_t)sizeof(opusInfo)) {
+ data_offset, opusInfo, opusInfoSize) < opusInfoSize) {
return ERROR_IO;
}
- // OpusHeader must start with this magic sequence
+ // OpusHeader must start with this magic sequence, overwrite first 8 bytes
// http://wiki.xiph.org/OggOpus#ID_Header
strncpy((char *)opusInfo, "OpusHead", 8);
@@ -1760,17 +1767,18 @@
memcpy(&opusInfo[opusOffset + 2], &sample_rate, sizeof(sample_rate));
memcpy(&opusInfo[opusOffset + 6], &out_gain, sizeof(out_gain));
- int64_t codecDelay = 6500000;
- int64_t seekPreRollNs = 80000000; // Fixed 80 msec
+ static const int64_t kSeekPreRollNs = 80000000; // Fixed 80 msec
+ static const int32_t kOpusSampleRate = 48000;
+ int64_t codecDelay = pre_skip * 1000000000ll / kOpusSampleRate;
AMediaFormat_setBuffer(mLastTrack->meta,
AMEDIAFORMAT_KEY_CSD_0, opusInfo, sizeof(opusInfo));
AMediaFormat_setBuffer(mLastTrack->meta,
AMEDIAFORMAT_KEY_CSD_1, &codecDelay, sizeof(codecDelay));
AMediaFormat_setBuffer(mLastTrack->meta,
- AMEDIAFORMAT_KEY_CSD_2, &seekPreRollNs, sizeof(seekPreRollNs));
+ AMEDIAFORMAT_KEY_CSD_2, &kSeekPreRollNs, sizeof(kSeekPreRollNs));
- data_offset += sizeof(opusInfo);
+ data_offset += opusInfoSize;
*offset = data_offset;
CHECK_EQ(*offset, stop_offset);
}
@@ -4297,6 +4305,77 @@
return ERROR_MALFORMED;
}
+ if (objectTypeIndication == 0xdd) {
+ // vorbis audio
+ if (csd[0] != 0x02) {
+ return ERROR_MALFORMED;
+ }
+
+ // codecInfo starts with two lengths, len1 and len2, that are
+ // "Xiph-style-lacing encoded"..
+
+ size_t offset = 1;
+ size_t len1 = 0;
+ while (offset < csd_size && csd[offset] == 0xff) {
+ if (__builtin_add_overflow(len1, 0xff, &len1)) {
+ return ERROR_MALFORMED;
+ }
+ ++offset;
+ }
+ if (offset >= csd_size) {
+ return ERROR_MALFORMED;
+ }
+ if (__builtin_add_overflow(len1, csd[offset], &len1)) {
+ return ERROR_MALFORMED;
+ }
+ ++offset;
+ if (len1 == 0) {
+ return ERROR_MALFORMED;
+ }
+
+ size_t len2 = 0;
+ while (offset < csd_size && csd[offset] == 0xff) {
+ if (__builtin_add_overflow(len2, 0xff, &len2)) {
+ return ERROR_MALFORMED;
+ }
+ ++offset;
+ }
+ if (offset >= csd_size) {
+ return ERROR_MALFORMED;
+ }
+ if (__builtin_add_overflow(len2, csd[offset], &len2)) {
+ return ERROR_MALFORMED;
+ }
+ ++offset;
+ if (len2 == 0) {
+ return ERROR_MALFORMED;
+ }
+ if (offset >= csd_size || csd[offset] != 0x01) {
+ return ERROR_MALFORMED;
+ }
+ // formerly kKeyVorbisInfo
+ AMediaFormat_setBuffer(mLastTrack->meta,
+ AMEDIAFORMAT_KEY_CSD_0, &csd[offset], len1);
+
+ if (__builtin_add_overflow(offset, len1, &offset) ||
+ offset >= csd_size || csd[offset] != 0x03) {
+ return ERROR_MALFORMED;
+ }
+
+ if (__builtin_add_overflow(offset, len2, &offset) ||
+ offset >= csd_size || csd[offset] != 0x05) {
+ return ERROR_MALFORMED;
+ }
+
+ // formerly kKeyVorbisBooks
+ AMediaFormat_setBuffer(mLastTrack->meta,
+ AMEDIAFORMAT_KEY_CSD_1, &csd[offset], csd_size - offset);
+ AMediaFormat_setString(mLastTrack->meta,
+ AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_AUDIO_VORBIS);
+
+ return OK;
+ }
+
static uint32_t kSamplingRate[] = {
96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050,
16000, 12000, 11025, 8000, 7350
diff --git a/media/libaudioclient/RecordingActivityTracker.cpp b/media/libaudioclient/RecordingActivityTracker.cpp
index bd10895..42d4361 100644
--- a/media/libaudioclient/RecordingActivityTracker.cpp
+++ b/media/libaudioclient/RecordingActivityTracker.cpp
@@ -36,6 +36,9 @@
RecordingActivityTracker::~RecordingActivityTracker()
{
+ if (mRIId != RECORD_RIID_INVALID && mAudioManager) {
+ mAudioManager->releaseRecorder(mRIId);
+ }
}
audio_unique_id_t RecordingActivityTracker::getRiid()
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp b/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp
index 2b813e7..865cb2a 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp
+++ b/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp
@@ -635,7 +635,7 @@
// re-init in case we prepare() and start() again.
delete mAnalyticsItem ;
- mAnalyticsItem = MediaAnalyticsItem::create("nuplayer");
+ mAnalyticsItem = MediaAnalyticsItem::create(kKeyPlayer);
if (mAnalyticsItem) {
mAnalyticsItem->setUid(mClientUid);
}
diff --git a/media/libstagefright/MediaExtractorFactory.cpp b/media/libstagefright/MediaExtractorFactory.cpp
index 81d2abb..4c8be1f 100644
--- a/media/libstagefright/MediaExtractorFactory.cpp
+++ b/media/libstagefright/MediaExtractorFactory.cpp
@@ -19,11 +19,11 @@
#include <utils/Log.h>
#include <android/dlext.h>
+#include <android-base/logging.h>
#include <binder/IPCThreadState.h>
#include <binder/PermissionCache.h>
#include <binder/IServiceManager.h>
#include <media/DataSource.h>
-#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/InterfaceUtils.h>
#include <media/stagefright/MediaExtractor.h>
#include <media/stagefright/MediaExtractorFactory.h>
@@ -71,8 +71,6 @@
ALOGV("MediaExtractorFactory::CreateFromService %s", mime);
- UpdateExtractors();
-
// initialize source decryption if needed
source->DrmInitialization(nullptr /* mime */);
@@ -245,21 +243,17 @@
void *libHandle = android_dlopen_ext(
libPath.string(),
RTLD_NOW | RTLD_LOCAL, dlextinfo);
- if (libHandle) {
- GetExtractorDef getDef =
- (GetExtractorDef) dlsym(libHandle, "GETEXTRACTORDEF");
- if (getDef) {
- ALOGV("registering sniffer for %s", libPath.string());
- RegisterExtractor(
- new ExtractorPlugin(getDef(), libHandle, libPath), pluginList);
- } else {
- LOG_ALWAYS_FATAL_IN_CHILD_PROC("%s does not contain sniffer", libPath.string());
- dlclose(libHandle);
- }
- } else {
- LOG_ALWAYS_FATAL_IN_CHILD_PROC(
- "couldn't dlopen(%s) %s", libPath.string(), strerror(errno));
- }
+ CHECK(libHandle != nullptr)
+ << "couldn't dlopen(" << libPath.string() << ") " << strerror(errno);
+
+ GetExtractorDef getDef =
+ (GetExtractorDef) dlsym(libHandle, "GETEXTRACTORDEF");
+ CHECK(getDef != nullptr)
+ << libPath.string() << " does not contain sniffer";
+
+ ALOGV("registering sniffer for %s", libPath.string());
+ RegisterExtractor(
+ new ExtractorPlugin(getDef(), libHandle, libPath), pluginList);
}
closedir(libDir);
} else {
@@ -274,7 +268,7 @@
static std::unordered_set<std::string> gSupportedExtensions;
// static
-void MediaExtractorFactory::UpdateExtractors() {
+void MediaExtractorFactory::LoadExtractors() {
Mutex::Autolock autoLock(gPluginMutex);
if (gPluginsRegistered) {
diff --git a/media/libstagefright/foundation/include/media/stagefright/foundation/ADebug.h b/media/libstagefright/foundation/include/media/stagefright/foundation/ADebug.h
index 37388a0..ab17a02 100644
--- a/media/libstagefright/foundation/include/media/stagefright/foundation/ADebug.h
+++ b/media/libstagefright/foundation/include/media/stagefright/foundation/ADebug.h
@@ -114,15 +114,6 @@
#define TRESPASS_DBG(...)
#endif
-#ifndef LOG_ALWAYS_FATAL_IN_CHILD_PROC
-#define LOG_ALWAYS_FATAL_IN_CHILD_PROC(...) \
- do { \
- if (fork() == 0) { \
- LOG_ALWAYS_FATAL(__VA_ARGS__); \
- } \
- } while (false)
-#endif
-
struct ADebug {
enum Level {
kDebugNone, // no debug
diff --git a/media/libstagefright/include/media/stagefright/MediaExtractorFactory.h b/media/libstagefright/include/media/stagefright/MediaExtractorFactory.h
index ea87948..2ab98e1 100644
--- a/media/libstagefright/include/media/stagefright/MediaExtractorFactory.h
+++ b/media/libstagefright/include/media/stagefright/MediaExtractorFactory.h
@@ -37,6 +37,7 @@
const sp<DataSource> &source, const char *mime = NULL);
static status_t dump(int fd, const Vector<String16>& args);
static std::unordered_set<std::string> getSupportedTypes();
+ static void LoadExtractors();
private:
static Mutex gPluginMutex;
@@ -53,8 +54,6 @@
static void *sniff(const sp<DataSource> &source,
float *confidence, void **meta, FreeMetaFunc *freeMeta,
sp<ExtractorPlugin> &plugin, uint32_t *creatorVersion);
-
- static void UpdateExtractors();
};
} // namespace android
diff --git a/media/libstagefright/xmlparser/MediaCodecsXmlParser.cpp b/media/libstagefright/xmlparser/MediaCodecsXmlParser.cpp
index 6a1b9a8..9783e9b 100644
--- a/media/libstagefright/xmlparser/MediaCodecsXmlParser.cpp
+++ b/media/libstagefright/xmlparser/MediaCodecsXmlParser.cpp
@@ -148,7 +148,7 @@
: mStatus(s),
mError(error) {
if (error.empty() && s) {
- error = "Failed (" + std::string(asString(s)) + ")";
+ mError = "Failed (" + std::string(asString(s)) + ")";
}
}
operator status_t() const { return mStatus; }
@@ -654,7 +654,7 @@
nextSection = SECTION_ENCODERS;
} else if (strEq(name, "Settings")) {
nextSection = SECTION_SETTINGS;
- } else if (strEq(name, "MediaCodecs")) {
+ } else if (strEq(name, "MediaCodecs") || strEq(name, "Included")) {
return;
} else {
break;
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 5e5ea11..66466b2 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -1900,12 +1900,16 @@
input.opPackageName,
&input.config,
output.flags, &output.selectedDeviceId, &portId);
+ if (lStatus != NO_ERROR) {
+ ALOGE("createRecord() getInputForAttr return error %d", lStatus);
+ goto Exit;
+ }
{
Mutex::Autolock _l(mLock);
RecordThread *thread = checkRecordThread_l(output.inputId);
if (thread == NULL) {
- ALOGE("createRecord() checkRecordThread_l failed");
+ ALOGE("createRecord() checkRecordThread_l failed, input handle %d", output.inputId);
lStatus = BAD_VALUE;
goto Exit;
}
diff --git a/services/audioflinger/PlaybackTracks.h b/services/audioflinger/PlaybackTracks.h
index bb97f8d..7008cee 100644
--- a/services/audioflinger/PlaybackTracks.h
+++ b/services/audioflinger/PlaybackTracks.h
@@ -26,7 +26,7 @@
bool hasOpPlayAudio() const;
static sp<OpPlayAudioMonitor> createIfNeeded(
- uid_t uid, audio_usage_t usage, int id, audio_stream_type_t streamType);
+ uid_t uid, const audio_attributes_t& attr, int id, audio_stream_type_t streamType);
private:
OpPlayAudioMonitor(uid_t uid, audio_usage_t usage, int id);
diff --git a/services/audioflinger/Tracks.cpp b/services/audioflinger/Tracks.cpp
index e1f00c1..b0817ed 100644
--- a/services/audioflinger/Tracks.cpp
+++ b/services/audioflinger/Tracks.cpp
@@ -387,18 +387,24 @@
// static
sp<AudioFlinger::PlaybackThread::OpPlayAudioMonitor>
AudioFlinger::PlaybackThread::OpPlayAudioMonitor::createIfNeeded(
- uid_t uid, audio_usage_t usage, int id, audio_stream_type_t streamType)
+ uid_t uid, const audio_attributes_t& attr, int id, audio_stream_type_t streamType)
{
if (isAudioServerOrRootUid(uid)) {
- ALOGD("OpPlayAudio: not muting track:%d usage:%d root or audioserver", id, usage);
+ ALOGD("OpPlayAudio: not muting track:%d usage:%d root or audioserver", id, attr.usage);
return nullptr;
}
// stream type has been filtered by audio policy to indicate whether it can be muted
if (streamType == AUDIO_STREAM_ENFORCED_AUDIBLE) {
- ALOGD("OpPlayAudio: not muting track:%d usage:%d ENFORCED_AUDIBLE", id, usage);
+ ALOGD("OpPlayAudio: not muting track:%d usage:%d ENFORCED_AUDIBLE", id, attr.usage);
return nullptr;
}
- return new OpPlayAudioMonitor(uid, usage, id);
+ if ((attr.flags & AUDIO_FLAG_BYPASS_INTERRUPTION_POLICY)
+ == AUDIO_FLAG_BYPASS_INTERRUPTION_POLICY) {
+ ALOGD("OpPlayAudio: not muting track:%d flags %#x have FLAG_BYPASS_INTERRUPTION_POLICY",
+ id, attr.flags);
+ return nullptr;
+ }
+ return new OpPlayAudioMonitor(uid, attr.usage, id);
}
AudioFlinger::PlaybackThread::OpPlayAudioMonitor::OpPlayAudioMonitor(
@@ -508,7 +514,7 @@
mPresentationCompleteFrames(0),
mFrameMap(16 /* sink-frame-to-track-frame map memory */),
mVolumeHandler(new media::VolumeHandler(sampleRate)),
- mOpPlayAudioMonitor(OpPlayAudioMonitor::createIfNeeded(uid, attr.usage, id(), streamType)),
+ mOpPlayAudioMonitor(OpPlayAudioMonitor::createIfNeeded(uid, attr, id(), streamType)),
// mSinkTimestamp
mFastIndex(-1),
mCachedVolume(1.0),
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index eaba828..d7dc51a 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -1991,16 +1991,25 @@
strncmp(attributes.tags, "addr=", strlen("addr=")) == 0) {
status = mPolicyMixes.getInputMixForAttr(attributes, &policyMix);
if (status != NO_ERROR) {
+ ALOGW("%s could not find input mix for attr %s",
+ __func__, toString(attributes).c_str());
goto error;
}
+ device = mAvailableInputDevices.getDevice(AUDIO_DEVICE_IN_REMOTE_SUBMIX,
+ String8(attr->tags + strlen("addr=")),
+ AUDIO_FORMAT_DEFAULT);
+ if (device == nullptr) {
+ ALOGW("%s could not find in Remote Submix device for source %d, tags %s",
+ __func__, attributes.source, attributes.tags);
+ status = BAD_VALUE;
+ goto error;
+ }
+
if (is_mix_loopback_render(policyMix->mRouteFlags)) {
*inputType = API_INPUT_MIX_PUBLIC_CAPTURE_PLAYBACK;
} else {
*inputType = API_INPUT_MIX_EXT_POLICY_REROUTE;
}
- device = mAvailableInputDevices.getDevice(AUDIO_DEVICE_IN_REMOTE_SUBMIX,
- String8(attr->tags + strlen("addr=")),
- AUDIO_FORMAT_DEFAULT);
} else {
if (explicitRoutingDevice != nullptr) {
device = explicitRoutingDevice;
@@ -2042,7 +2051,7 @@
device->getId() : AUDIO_PORT_HANDLE_NONE;
isSoundTrigger = attributes.source == AUDIO_SOURCE_HOTWORD &&
- mSoundTriggerSessions.indexOfKey(session) > 0;
+ mSoundTriggerSessions.indexOfKey(session) >= 0;
*portId = AudioPort::getNextUniqueId();
clientDesc = new RecordClientDescriptor(*portId, riid, uid, session, attributes, *config,
@@ -2867,14 +2876,12 @@
rSubmixModule->addInputProfile(address, &inputConfig,
AUDIO_DEVICE_IN_REMOTE_SUBMIX, address);
- if (mix.mMixType == MIX_TYPE_PLAYERS) {
- setDeviceConnectionStateInt(AUDIO_DEVICE_IN_REMOTE_SUBMIX,
- AUDIO_POLICY_DEVICE_STATE_AVAILABLE,
- address.string(), "remote-submix", AUDIO_FORMAT_DEFAULT);
- } else {
- setDeviceConnectionStateInt(AUDIO_DEVICE_OUT_REMOTE_SUBMIX,
- AUDIO_POLICY_DEVICE_STATE_AVAILABLE,
- address.string(), "remote-submix", AUDIO_FORMAT_DEFAULT);
+ if ((res = setDeviceConnectionStateInt(mix.mDeviceType,
+ AUDIO_POLICY_DEVICE_STATE_AVAILABLE,
+ address.string(), "remote-submix", AUDIO_FORMAT_DEFAULT)) != NO_ERROR) {
+ ALOGE("Failed to set remote submix device available, type %u, address %s",
+ mix.mDeviceType, address.string());
+ break;
}
} else if ((mix.mRouteFlags & MIX_ROUTE_FLAG_RENDER) == MIX_ROUTE_FLAG_RENDER) {
String8 address = mix.mDeviceAddress;
@@ -2950,17 +2957,17 @@
continue;
}
- if (getDeviceConnectionState(AUDIO_DEVICE_IN_REMOTE_SUBMIX, address.string()) ==
- AUDIO_POLICY_DEVICE_STATE_AVAILABLE) {
- setDeviceConnectionStateInt(AUDIO_DEVICE_IN_REMOTE_SUBMIX,
- AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE,
- address.string(), "remote-submix", AUDIO_FORMAT_DEFAULT);
- }
- if (getDeviceConnectionState(AUDIO_DEVICE_OUT_REMOTE_SUBMIX, address.string()) ==
- AUDIO_POLICY_DEVICE_STATE_AVAILABLE) {
- setDeviceConnectionStateInt(AUDIO_DEVICE_OUT_REMOTE_SUBMIX,
- AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE,
- address.string(), "remote-submix", AUDIO_FORMAT_DEFAULT);
+ for (auto device : {AUDIO_DEVICE_IN_REMOTE_SUBMIX, AUDIO_DEVICE_OUT_REMOTE_SUBMIX}) {
+ if (getDeviceConnectionState(device, address.string()) ==
+ AUDIO_POLICY_DEVICE_STATE_AVAILABLE) {
+ res = setDeviceConnectionStateInt(device, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE,
+ address.string(), "remote-submix",
+ AUDIO_FORMAT_DEFAULT);
+ if (res != OK) {
+ ALOGE("Error making RemoteSubmix device unavailable for mix "
+ "with type %d, address %s", device, address.string());
+ }
+ }
}
rSubmixModule->removeOutputProfile(address);
rSubmixModule->removeInputProfile(address);
diff --git a/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp b/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
index 06e68a9..07a5a43 100644
--- a/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
+++ b/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
@@ -511,6 +511,7 @@
}
// including successes gets very verbose
+ // but once we cut over to westworld, log them all.
if (status != NO_ERROR) {
static constexpr char kAudioPolicy[] = "audiopolicy";
@@ -571,6 +572,9 @@
delete item;
item = NULL;
}
+ }
+
+ if (status != NO_ERROR) {
client->active = false;
client->startTimeNs = 0;
updateUidStates_l();
diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
index fc6d6be..a87ebdf 100644
--- a/services/camera/libcameraservice/CameraService.cpp
+++ b/services/camera/libcameraservice/CameraService.cpp
@@ -117,6 +117,11 @@
static const String16 sManageCameraPermission("android.permission.MANAGE_CAMERA");
+// Matches with PERCEPTIBLE_APP_ADJ in ProcessList.java
+static constexpr int32_t kVendorClientScore = 200;
+// Matches with PROCESS_STATE_PERSISTENT_UI in ActivityManager.java
+static constexpr int32_t kVendorClientState = 1;
+
Mutex CameraService::sProxyMutex;
sp<hardware::ICameraServiceProxy> CameraService::sCameraServiceProxy;
@@ -1120,7 +1125,8 @@
std::map<int,resource_policy::ClientPriority> pidToPriorityMap;
for (size_t i = 0; i < ownerPids.size() - 1; i++) {
pidToPriorityMap.emplace(ownerPids[i],
- resource_policy::ClientPriority(priorityScores[i], states[i]));
+ resource_policy::ClientPriority(priorityScores[i], states[i],
+ /* isVendorClient won't get copied over*/ false));
}
mActiveClientManager.updatePriorities(pidToPriorityMap);
@@ -2980,8 +2986,12 @@
const std::set<String8>& conflictingKeys, int32_t score, int32_t ownerId,
int32_t state) {
+ bool isVendorClient = hardware::IPCThreadState::self()->isServingCall();
+ int32_t score_adj = isVendorClient ? kVendorClientScore : score;
+ int32_t state_adj = isVendorClient ? kVendorClientState: state;
+
return std::make_shared<resource_policy::ClientDescriptor<String8, sp<BasicClient>>>(
- key, value, cost, conflictingKeys, score, ownerId, state);
+ key, value, cost, conflictingKeys, score_adj, ownerId, state_adj, isVendorClient);
}
CameraService::DescriptorPtr CameraService::CameraClientManager::makeClientDescriptor(
diff --git a/services/camera/libcameraservice/utils/ClientManager.h b/services/camera/libcameraservice/utils/ClientManager.h
index d7135f1..ec6f01c 100644
--- a/services/camera/libcameraservice/utils/ClientManager.h
+++ b/services/camera/libcameraservice/utils/ClientManager.h
@@ -33,12 +33,38 @@
class ClientPriority {
public:
- ClientPriority(int32_t score, int32_t state) :
- mScore(score), mState(state) {}
+ /**
+ * Choosing to set mIsVendorClient through a parameter instead of calling
+ * hardware::IPCThreadState::self()->isServingCall() to protect against the
+ * case where the construction is offloaded to another thread which isn't a
+ * hwbinder thread.
+ */
+ ClientPriority(int32_t score, int32_t state, bool isVendorClient) :
+ mScore(score), mState(state), mIsVendorClient(isVendorClient) { }
int32_t getScore() const { return mScore; }
int32_t getState() const { return mState; }
+ void setScore(int32_t score) {
+ // For vendor clients, the score is set once and for all during
+ // construction. Otherwise, it can get reset each time cameraserver
+ // queries ActivityManagerService for oom_adj scores / states .
+ if (!mIsVendorClient) {
+ mScore = score;
+ }
+ }
+
+ void setState(int32_t state) {
+ // For vendor clients, the score is set once and for all during
+ // construction. Otherwise, it can get reset each time cameraserver
+ // queries ActivityManagerService for oom_adj scores / states
+ // (ActivityManagerService returns a vendor process' state as
+ // PROCESS_STATE_NONEXISTENT.
+ if (!mIsVendorClient) {
+ mState = state;
+ }
+ }
+
bool operator==(const ClientPriority& rhs) const {
return (this->mScore == rhs.mScore) && (this->mState == rhs.mState);
}
@@ -66,6 +92,7 @@
private:
int32_t mScore;
int32_t mState;
+ bool mIsVendorClient = false;
};
// --------------------------------------------------------------------------------
@@ -82,9 +109,10 @@
class ClientDescriptor final {
public:
ClientDescriptor(const KEY& key, const VALUE& value, int32_t cost,
- const std::set<KEY>& conflictingKeys, int32_t score, int32_t ownerId, int32_t state);
+ const std::set<KEY>& conflictingKeys, int32_t score, int32_t ownerId, int32_t state,
+ bool isVendorClient);
ClientDescriptor(KEY&& key, VALUE&& value, int32_t cost, std::set<KEY>&& conflictingKeys,
- int32_t score, int32_t ownerId, int32_t state);
+ int32_t score, int32_t ownerId, int32_t state, bool isVendorClient);
~ClientDescriptor();
@@ -148,17 +176,19 @@
template<class KEY, class VALUE>
ClientDescriptor<KEY, VALUE>::ClientDescriptor(const KEY& key, const VALUE& value, int32_t cost,
- const std::set<KEY>& conflictingKeys, int32_t score, int32_t ownerId, int32_t state) :
+ const std::set<KEY>& conflictingKeys, int32_t score, int32_t ownerId, int32_t state,
+ bool isVendorClient) :
mKey{key}, mValue{value}, mCost{cost}, mConflicting{conflictingKeys},
- mPriority(score, state),
+ mPriority(score, state, isVendorClient),
mOwnerId{ownerId} {}
template<class KEY, class VALUE>
ClientDescriptor<KEY, VALUE>::ClientDescriptor(KEY&& key, VALUE&& value, int32_t cost,
- std::set<KEY>&& conflictingKeys, int32_t score, int32_t ownerId, int32_t state) :
+ std::set<KEY>&& conflictingKeys, int32_t score, int32_t ownerId, int32_t state,
+ bool isVendorClient) :
mKey{std::forward<KEY>(key)}, mValue{std::forward<VALUE>(value)}, mCost{cost},
mConflicting{std::forward<std::set<KEY>>(conflictingKeys)},
- mPriority(score, state), mOwnerId{ownerId} {}
+ mPriority(score, state, isVendorClient), mOwnerId{ownerId} {}
template<class KEY, class VALUE>
ClientDescriptor<KEY, VALUE>::~ClientDescriptor() {}
@@ -204,7 +234,13 @@
template<class KEY, class VALUE>
void ClientDescriptor<KEY, VALUE>::setPriority(const ClientPriority& priority) {
- mPriority = priority;
+ // We don't use the usual copy constructor here since we want to remember
+ // whether a client is a vendor client or not. This could have been wiped
+ // off in the incoming priority argument since an AIDL thread might have
+ // called hardware::IPCThreadState::self()->isServingCall() after refreshing
+ // priorities for old clients through ProcessInfoService::getProcessStatesScoresFromPids().
+ mPriority.setScore(priority.getScore());
+ mPriority.setState(priority.getState());
}
// --------------------------------------------------------------------------------
diff --git a/services/mediaanalytics/Android.bp b/services/mediaanalytics/Android.bp
index c93c120..72f4b52 100644
--- a/services/mediaanalytics/Android.bp
+++ b/services/mediaanalytics/Android.bp
@@ -7,8 +7,22 @@
srcs: [
"main_mediametrics.cpp",
"MediaAnalyticsService.cpp",
+ "iface_statsd.cpp",
+ "statsd_audiopolicy.cpp",
+ "statsd_audiorecord.cpp",
+ "statsd_audiothread.cpp",
+ "statsd_audiotrack.cpp",
+ "statsd_codec.cpp",
+ "statsd_drm.cpp",
+ "statsd_extractor.cpp",
+ "statsd_nuplayer.cpp",
+ "statsd_recorder.cpp",
],
+ proto: {
+ type: "lite",
+ },
+
shared_libs: [
"libcutils",
"liblog",
@@ -21,10 +35,15 @@
"libmediautils",
"libmediametrics",
"libstagefright_foundation",
+ "libstatslog",
"libutils",
+ "libprotobuf-cpp-lite",
],
- static_libs: ["libregistermsext"],
+ static_libs: [
+ "libplatformprotos",
+ "libregistermsext",
+ ],
include_dirs: [
"frameworks/av/media/libstagefright/include",
diff --git a/services/mediaanalytics/MediaAnalyticsService.cpp b/services/mediaanalytics/MediaAnalyticsService.cpp
index 06baac9..3626ad1 100644
--- a/services/mediaanalytics/MediaAnalyticsService.cpp
+++ b/services/mediaanalytics/MediaAnalyticsService.cpp
@@ -210,21 +210,24 @@
// XXX: if we have a sessionid in the new record, look to make
// sure it doesn't appear in the finalized list.
- // XXX: this is for security / DOS prevention.
- // may also require that we persist the unique sessionIDs
- // across boots [instead of within a single boot]
if (item->count() == 0) {
- // drop empty records
+ ALOGV("dropping empty record...");
delete item;
item = NULL;
return MediaAnalyticsItem::SessionIDInvalid;
}
// save the new record
+ //
+ // send a copy to statsd
+ dump2Statsd(item);
+
+ // and keep our copy for dumpsys
MediaAnalyticsItem::SessionID_t id = item->getSessionID();
saveItem(item);
mItemsFinalized++;
+
return id;
}
diff --git a/services/mediaanalytics/MediaAnalyticsService.h b/services/mediaanalytics/MediaAnalyticsService.h
index 632c692..6c9cbaa 100644
--- a/services/mediaanalytics/MediaAnalyticsService.h
+++ b/services/mediaanalytics/MediaAnalyticsService.h
@@ -112,6 +112,9 @@
};
+// hook to send things off to the statsd subsystem
+extern bool dump2Statsd(MediaAnalyticsItem *item);
+
// ----------------------------------------------------------------------------
}; // namespace android
diff --git a/services/mediaanalytics/iface_statsd.cpp b/services/mediaanalytics/iface_statsd.cpp
new file mode 100644
index 0000000..6845f06
--- /dev/null
+++ b/services/mediaanalytics/iface_statsd.cpp
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2019 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 "iface_statsd"
+#include <utils/Log.h>
+
+#include <stdint.h>
+#include <inttypes.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <dirent.h>
+#include <pthread.h>
+#include <unistd.h>
+
+#include <string.h>
+#include <pwd.h>
+
+#include "MediaAnalyticsService.h"
+#include "iface_statsd.h"
+
+#include <statslog.h>
+
+namespace android {
+
+// set of routines that crack a MediaAnalyticsItem
+// and send it off to statsd with the appropriate hooks
+//
+// each MediaAnalyticsItem type (extractor, codec, nuplayer, etc)
+// has its own routine to handle this.
+//
+
+bool enabled_statsd = true;
+
+struct statsd_hooks {
+ const char *key;
+ bool (*handler)(MediaAnalyticsItem *);
+};
+
+// keep this sorted, so we can do binary searches
+struct statsd_hooks statsd_handlers[] =
+{
+ { "audiopolicy", statsd_audiopolicy },
+ { "audiorecord", statsd_audiorecord },
+ { "audiothread", statsd_audiothread },
+ { "audiotrack", statsd_audiotrack },
+ { "codec", statsd_codec},
+ { "drm.vendor.Google.WidevineCDM", statsd_widevineCDM },
+ { "extractor", statsd_extractor },
+ { "mediadrm", statsd_mediadrm },
+ { "nuplayer", statsd_nuplayer },
+ { "nuplayer2", statsd_nuplayer },
+ { "recorder", statsd_recorder },
+};
+
+
+// give me a record, i'll look at the type and upload appropriately
+bool dump2Statsd(MediaAnalyticsItem *item) {
+ if (item == NULL) return false;
+
+ // get the key
+ std::string key = item->getKey();
+
+ if (!enabled_statsd) {
+ ALOGV("statsd logging disabled for record key=%s", key.c_str());
+ return false;
+ }
+
+ int i;
+ for(i = 0;i < sizeof(statsd_handlers) / sizeof(statsd_handlers[0]) ; i++) {
+ if (key == statsd_handlers[i].key) {
+ return (*statsd_handlers[i].handler)(item);
+ }
+ }
+ return false;
+}
+
+} // namespace android
diff --git a/services/mediaanalytics/iface_statsd.h b/services/mediaanalytics/iface_statsd.h
new file mode 100644
index 0000000..f85d303
--- /dev/null
+++ b/services/mediaanalytics/iface_statsd.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+namespace android {
+
+extern bool enabled_statsd;
+
+// component specific dumpers
+extern bool statsd_audiopolicy(MediaAnalyticsItem *);
+extern bool statsd_audiorecord(MediaAnalyticsItem *);
+extern bool statsd_audiothread(MediaAnalyticsItem *);
+extern bool statsd_audiotrack(MediaAnalyticsItem *);
+extern bool statsd_codec(MediaAnalyticsItem *);
+extern bool statsd_extractor(MediaAnalyticsItem *);
+extern bool statsd_nuplayer(MediaAnalyticsItem *);
+extern bool statsd_recorder(MediaAnalyticsItem *);
+
+extern bool statsd_mediadrm(MediaAnalyticsItem *);
+extern bool statsd_widevineCDM(MediaAnalyticsItem *);
+
+} // namespace android
diff --git a/services/mediaanalytics/statsd_audiopolicy.cpp b/services/mediaanalytics/statsd_audiopolicy.cpp
new file mode 100644
index 0000000..06c4dde
--- /dev/null
+++ b/services/mediaanalytics/statsd_audiopolicy.cpp
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2019 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 "statsd_audiopolicy"
+#include <utils/Log.h>
+
+#include <dirent.h>
+#include <inttypes.h>
+#include <pthread.h>
+#include <pwd.h>
+#include <stdint.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <statslog.h>
+
+#include "MediaAnalyticsService.h"
+#include "frameworks/base/core/proto/android/stats/mediametrics/mediametrics.pb.h"
+#include "iface_statsd.h"
+
+namespace android {
+
+bool statsd_audiopolicy(MediaAnalyticsItem *item)
+{
+ if (item == NULL) return false;
+
+ // these go into the statsd wrapper
+ nsecs_t timestamp = item->getTimestamp();
+ std::string pkgName = item->getPkgName();
+ int64_t pkgVersionCode = item->getPkgVersionCode();
+ int64_t mediaApexVersion = 0;
+
+
+ // the rest into our own proto
+ //
+ ::android::stats::mediametrics::AudioPolicyData metrics_proto;
+
+ // flesh out the protobuf we'll hand off with our data
+ //
+ //int32 char kAudioPolicyStatus[] = "android.media.audiopolicy.status";
+ int32_t status = -1;
+ if (item->getInt32("android.media.audiopolicy.status", &status)) {
+ metrics_proto.set_status(status);
+ }
+ //string char kAudioPolicyRqstSrc[] = "android.media.audiopolicy.rqst.src";
+ char *rqst_src = NULL;
+ if (item->getCString("android.media.audiopolicy.rqst.src", &rqst_src)) {
+ metrics_proto.set_request_source(rqst_src);
+ }
+ //string char kAudioPolicyRqstPkg[] = "android.media.audiopolicy.rqst.pkg";
+ char *rqst_pkg = NULL;
+ if (item->getCString("android.media.audiopolicy.rqst.pkg", &rqst_pkg)) {
+ metrics_proto.set_request_package(rqst_pkg);
+ }
+ //int32 char kAudioPolicyRqstSession[] = "android.media.audiopolicy.rqst.session";
+ int32_t rqst_session = -1;
+ if (item->getInt32("android.media.audiopolicy.rqst.session", &rqst_session)) {
+ metrics_proto.set_request_session(rqst_session);
+ }
+ //string char kAudioPolicyRqstDevice[] = "android.media.audiopolicy.rqst.device";
+ char *rqst_device = NULL;
+ if (item->getCString("android.media.audiopolicy.rqst.device", &rqst_device)) {
+ metrics_proto.set_request_device(rqst_device);
+ }
+
+ //string char kAudioPolicyActiveSrc[] = "android.media.audiopolicy.active.src";
+ char *active_src = NULL;
+ if (item->getCString("android.media.audiopolicy.active.src", &active_src)) {
+ metrics_proto.set_active_source(active_src);
+ }
+ //string char kAudioPolicyActivePkg[] = "android.media.audiopolicy.active.pkg";
+ char *active_pkg = NULL;
+ if (item->getCString("android.media.audiopolicy.active.pkg", &active_pkg)) {
+ metrics_proto.set_active_package(active_pkg);
+ }
+ //int32 char kAudioPolicyActiveSession[] = "android.media.audiopolicy.active.session";
+ int32_t active_session = -1;
+ if (item->getInt32("android.media.audiopolicy.active.session", &active_session)) {
+ metrics_proto.set_active_session(active_session);
+ }
+ //string char kAudioPolicyActiveDevice[] = "android.media.audiopolicy.active.device";
+ char *active_device = NULL;
+ if (item->getCString("android.media.audiopolicy.active.device", &active_device)) {
+ metrics_proto.set_active_device(active_device);
+ }
+
+
+ std::string serialized;
+ if (!metrics_proto.SerializeToString(&serialized)) {
+ ALOGE("Failed to serialize audipolicy metrics");
+ return false;
+ }
+
+ if (enabled_statsd) {
+ android::util::BytesField bf_serialized( serialized.c_str(), serialized.size());
+ (void)android::util::stats_write(android::util::MEDIAMETRICS_AUDIOPOLICY_REPORTED,
+ timestamp, pkgName.c_str(), pkgVersionCode,
+ mediaApexVersion,
+ bf_serialized);
+
+ } else {
+ ALOGV("NOT sending: private data (len=%zu)", strlen(serialized.c_str()));
+ }
+
+ // must free the strings that we were given
+ free(rqst_src);
+ free(rqst_pkg);
+ free(rqst_device);
+ free(active_src);
+ free(active_pkg);
+ free(active_device);
+
+ return true;
+}
+
+};
diff --git a/services/mediaanalytics/statsd_audiorecord.cpp b/services/mediaanalytics/statsd_audiorecord.cpp
new file mode 100644
index 0000000..c9edb27
--- /dev/null
+++ b/services/mediaanalytics/statsd_audiorecord.cpp
@@ -0,0 +1,164 @@
+/*
+ * Copyright (C) 2019 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 "statsd_audiorecord"
+#include <utils/Log.h>
+
+#include <dirent.h>
+#include <inttypes.h>
+#include <pthread.h>
+#include <pwd.h>
+#include <stdint.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <statslog.h>
+
+#include "MediaAnalyticsService.h"
+#include "frameworks/base/core/proto/android/stats/mediametrics/mediametrics.pb.h"
+#include "iface_statsd.h"
+
+namespace android {
+
+bool statsd_audiorecord(MediaAnalyticsItem *item)
+{
+ if (item == NULL) return false;
+
+ // these go into the statsd wrapper
+ nsecs_t timestamp = item->getTimestamp();
+ std::string pkgName = item->getPkgName();
+ int64_t pkgVersionCode = item->getPkgVersionCode();
+ int64_t mediaApexVersion = 0;
+
+
+ // the rest into our own proto
+ //
+ ::android::stats::mediametrics::AudioRecordData metrics_proto;
+
+ // flesh out the protobuf we'll hand off with our data
+ //
+ char *encoding = NULL;
+ if (item->getCString("android.media.audiorecord.encoding", &encoding)) {
+ metrics_proto.set_encoding(encoding);
+ }
+
+ char *source = NULL;
+ if (item->getCString("android.media.audiorecord.source", &source)) {
+ metrics_proto.set_source(source);
+ }
+
+ int32_t latency = -1;
+ if (item->getInt32("android.media.audiorecord.latency", &latency)) {
+ metrics_proto.set_latency(latency);
+ }
+
+ int32_t samplerate = -1;
+ if (item->getInt32("android.media.audiorecord.samplerate", &samplerate)) {
+ metrics_proto.set_samplerate(samplerate);
+ }
+
+ int32_t channels = -1;
+ if (item->getInt32("android.media.audiorecord.channels", &channels)) {
+ metrics_proto.set_channels(channels);
+ }
+
+ int64_t createdMs = -1;
+ if (item->getInt64("android.media.audiorecord.createdMs", &createdMs)) {
+ metrics_proto.set_created_millis(createdMs);
+ }
+
+ int64_t durationMs = -1;
+ if (item->getInt64("android.media.audiorecord.durationMs", &durationMs)) {
+ metrics_proto.set_duration_millis(durationMs);
+ }
+
+ int32_t count = -1;
+ if (item->getInt32("android.media.audiorecord.n", &count)) {
+ metrics_proto.set_count(count);
+ }
+
+ int32_t errcode = -1;
+ if (item->getInt32("android.media.audiorecord.errcode", &errcode)) {
+ metrics_proto.set_error_code(errcode);
+ } else if (item->getInt32("android.media.audiorecord.lastError.code", &errcode)) {
+ metrics_proto.set_error_code(errcode);
+ }
+
+ char *errfunc = NULL;
+ if (item->getCString("android.media.audiorecord.errfunc", &errfunc)) {
+ metrics_proto.set_error_function(errfunc);
+ } else if (item->getCString("android.media.audiorecord.lastError.at", &errfunc)) {
+ metrics_proto.set_error_function(errfunc);
+ }
+
+ // portId (int32)
+ int32_t port_id = -1;
+ if (item->getInt32("android.media.audiorecord.portId", &port_id)) {
+ metrics_proto.set_port_id(count);
+ }
+ // frameCount (int32)
+ int32_t frameCount = -1;
+ if (item->getInt32("android.media.audiorecord.frameCount", &frameCount)) {
+ metrics_proto.set_frame_count(frameCount);
+ }
+ // attributes (string)
+ char *attributes = NULL;
+ if (item->getCString("android.media.audiorecord.attributes", &attributes)) {
+ metrics_proto.set_attributes(attributes);
+ }
+ // channelMask (int64)
+ int64_t channelMask = -1;
+ if (item->getInt64("android.media.audiorecord.channelMask", &channelMask)) {
+ metrics_proto.set_channel_mask(channelMask);
+ }
+ // startcount (int64)
+ int64_t startcount = -1;
+ if (item->getInt64("android.media.audiorecord.startcount", &startcount)) {
+ metrics_proto.set_start_count(startcount);
+ }
+
+
+ std::string serialized;
+ if (!metrics_proto.SerializeToString(&serialized)) {
+ ALOGE("Failed to serialize audiorecord metrics");
+ return false;
+ }
+
+ if (enabled_statsd) {
+ android::util::BytesField bf_serialized( serialized.c_str(), serialized.size());
+ (void)android::util::stats_write(android::util::MEDIAMETRICS_AUDIORECORD_REPORTED,
+ timestamp, pkgName.c_str(), pkgVersionCode,
+ mediaApexVersion,
+ bf_serialized);
+
+ } else {
+ ALOGV("NOT sending: private data (len=%zu)", strlen(serialized.c_str()));
+ }
+
+ // must free the strings that we were given
+ free(encoding);
+ free(source);
+ free(errfunc);
+ free(attributes);
+
+ return true;
+}
+
+};
diff --git a/services/mediaanalytics/statsd_audiothread.cpp b/services/mediaanalytics/statsd_audiothread.cpp
new file mode 100644
index 0000000..8232424
--- /dev/null
+++ b/services/mediaanalytics/statsd_audiothread.cpp
@@ -0,0 +1,217 @@
+/*
+ * Copyright (C) 2019 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 "statsd_audiothread"
+#include <utils/Log.h>
+
+#include <dirent.h>
+#include <inttypes.h>
+#include <pthread.h>
+#include <pwd.h>
+#include <stdint.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <statslog.h>
+
+#include "MediaAnalyticsService.h"
+#include "frameworks/base/core/proto/android/stats/mediametrics/mediametrics.pb.h"
+#include "iface_statsd.h"
+
+namespace android {
+
+bool statsd_audiothread(MediaAnalyticsItem *item)
+{
+ if (item == NULL) return false;
+
+ // these go into the statsd wrapper
+ nsecs_t timestamp = item->getTimestamp();
+ std::string pkgName = item->getPkgName();
+ int64_t pkgVersionCode = item->getPkgVersionCode();
+ int64_t mediaApexVersion = 0;
+
+
+ // the rest into our own proto
+ //
+ ::android::stats::mediametrics::AudioThreadData metrics_proto;
+
+#define MM_PREFIX "android.media.audiothread."
+
+ // flesh out the protobuf we'll hand off with our data
+ //
+ char *mytype = NULL;
+ if (item->getCString(MM_PREFIX "type", &mytype)) {
+ metrics_proto.set_type(mytype);
+ }
+ int32_t framecount = -1;
+ if (item->getInt32(MM_PREFIX "framecount", &framecount)) {
+ metrics_proto.set_framecount(framecount);
+ }
+ int32_t samplerate = -1;
+ if (item->getInt32(MM_PREFIX "samplerate", &samplerate)) {
+ metrics_proto.set_samplerate(samplerate);
+ }
+ char *workhist = NULL;
+ if (item->getCString(MM_PREFIX "workMs.hist", &workhist)) {
+ metrics_proto.set_work_millis_hist(workhist);
+ }
+ char *latencyhist = NULL;
+ if (item->getCString(MM_PREFIX "latencyMs.hist", &latencyhist)) {
+ metrics_proto.set_latency_millis_hist(latencyhist);
+ }
+ char *warmuphist = NULL;
+ if (item->getCString(MM_PREFIX "warmupMs.hist", &warmuphist)) {
+ metrics_proto.set_warmup_millis_hist(warmuphist);
+ }
+ int64_t underruns = -1;
+ if (item->getInt64(MM_PREFIX "underruns", &underruns)) {
+ metrics_proto.set_underruns(underruns);
+ }
+ int64_t overruns = -1;
+ if (item->getInt64(MM_PREFIX "overruns", &overruns)) {
+ metrics_proto.set_overruns(overruns);
+ }
+ int64_t activeMs = -1;
+ if (item->getInt64(MM_PREFIX "activeMs", &activeMs)) {
+ metrics_proto.set_active_millis(activeMs);
+ }
+ int64_t durationMs = -1;
+ if (item->getInt64(MM_PREFIX "durationMs", &durationMs)) {
+ metrics_proto.set_duration_millis(durationMs);
+ }
+
+ // item->setInt32(MM_PREFIX "id", (int32_t)mId); // IO handle
+ int32_t id = -1;
+ if (item->getInt32(MM_PREFIX "id", &id)) {
+ metrics_proto.set_id(id);
+ }
+ // item->setInt32(MM_PREFIX "portId", (int32_t)mPortId);
+ int32_t port_id = -1;
+ if (item->getInt32(MM_PREFIX "portId", &id)) {
+ metrics_proto.set_port_id(port_id);
+ }
+ // item->setCString(MM_PREFIX "type", threadTypeToString(mType));
+ char *type = NULL;
+ if (item->getCString(MM_PREFIX "type", &type)) {
+ metrics_proto.set_type(type);
+ }
+ // item->setInt32(MM_PREFIX "sampleRate", (int32_t)mSampleRate);
+ int32_t sample_rate = -1;
+ if (item->getInt32(MM_PREFIX "sampleRate", &sample_rate)) {
+ metrics_proto.set_sample_rate(sample_rate);
+ }
+ // item->setInt64(MM_PREFIX "channelMask", (int64_t)mChannelMask);
+ int32_t channel_mask = -1;
+ if (item->getInt32(MM_PREFIX "channelMask", &channel_mask)) {
+ metrics_proto.set_channel_mask(channel_mask);
+ }
+ // item->setCString(MM_PREFIX "encoding", toString(mFormat).c_str());
+ char *encoding = NULL;
+ if (item->getCString(MM_PREFIX "encoding", &encoding)) {
+ metrics_proto.set_encoding(encoding);
+ }
+ // item->setInt32(MM_PREFIX "frameCount", (int32_t)mFrameCount);
+ int32_t frame_count = -1;
+ if (item->getInt32(MM_PREFIX "frameCount", &frame_count)) {
+ metrics_proto.set_frame_count(frame_count);
+ }
+ // item->setCString(MM_PREFIX "outDevice", toString(mOutDevice).c_str());
+ char *outDevice = NULL;
+ if (item->getCString(MM_PREFIX "outDevice", &outDevice)) {
+ metrics_proto.set_output_device(outDevice);
+ }
+ // item->setCString(MM_PREFIX "inDevice", toString(mInDevice).c_str());
+ char *inDevice = NULL;
+ if (item->getCString(MM_PREFIX "inDevice", &inDevice)) {
+ metrics_proto.set_input_device(inDevice);
+ }
+ // item->setDouble(MM_PREFIX "ioJitterMs.mean", mIoJitterMs.getMean());
+ double iojitters_ms_mean = -1;
+ if (item->getDouble(MM_PREFIX "ioJitterMs.mean", &iojitters_ms_mean)) {
+ metrics_proto.set_io_jitter_mean_millis(iojitters_ms_mean);
+ }
+ // item->setDouble(MM_PREFIX "ioJitterMs.std", mIoJitterMs.getStdDev());
+ double iojitters_ms_std = -1;
+ if (item->getDouble(MM_PREFIX "ioJitterMs.std", &iojitters_ms_std)) {
+ metrics_proto.set_io_jitter_stddev_millis(iojitters_ms_std);
+ }
+ // item->setDouble(MM_PREFIX "processTimeMs.mean", mProcessTimeMs.getMean());
+ double process_time_ms_mean = -1;
+ if (item->getDouble(MM_PREFIX "processTimeMs.mean", &process_time_ms_mean)) {
+ metrics_proto.set_process_time_mean_millis(process_time_ms_mean);
+ }
+ // item->setDouble(MM_PREFIX "processTimeMs.std", mProcessTimeMs.getStdDev());
+ double process_time_ms_std = -1;
+ if (item->getDouble(MM_PREFIX "processTimeMs.std", &process_time_ms_std)) {
+ metrics_proto.set_process_time_stddev_millis(process_time_ms_std);
+ }
+ // item->setDouble(MM_PREFIX "timestampJitterMs.mean", tsjitter.getMean());
+ double timestamp_jitter_ms_mean = -1;
+ if (item->getDouble(MM_PREFIX "timestampJitterMs.mean", ×tamp_jitter_ms_mean)) {
+ metrics_proto.set_timestamp_jitter_mean_millis(timestamp_jitter_ms_mean);
+ }
+ // item->setDouble(MM_PREFIX "timestampJitterMs.std", tsjitter.getStdDev());
+ double timestamp_jitter_ms_stddev = -1;
+ if (item->getDouble(MM_PREFIX "timestampJitterMs.std", ×tamp_jitter_ms_stddev)) {
+ metrics_proto.set_timestamp_jitter_stddev_millis(timestamp_jitter_ms_stddev);
+ }
+ // item->setDouble(MM_PREFIX "latencyMs.mean", mLatencyMs.getMean());
+ double latency_ms_mean = -1;
+ if (item->getDouble(MM_PREFIX "latencyMs.mean", &latency_ms_mean)) {
+ metrics_proto.set_latency_mean_millis(latency_ms_mean);
+ }
+ // item->setDouble(MM_PREFIX "latencyMs.std", mLatencyMs.getStdDev());
+ double latency_ms_stddev = -1;
+ if (item->getDouble(MM_PREFIX "latencyMs.std", &latency_ms_stddev)) {
+ metrics_proto.set_latency_stddev_millis(latency_ms_stddev);
+ }
+
+
+ std::string serialized;
+ if (!metrics_proto.SerializeToString(&serialized)) {
+ ALOGE("Failed to serialize audiothread metrics");
+ return false;
+ }
+
+ if (enabled_statsd) {
+ android::util::BytesField bf_serialized( serialized.c_str(), serialized.size());
+ (void)android::util::stats_write(android::util::MEDIAMETRICS_AUDIOTHREAD_REPORTED,
+ timestamp, pkgName.c_str(), pkgVersionCode,
+ mediaApexVersion,
+ bf_serialized);
+
+ } else {
+ ALOGV("NOT sending: private data (len=%zu)", strlen(serialized.c_str()));
+ }
+
+ // must free the strings that we were given
+ free(mytype);
+ free(workhist);
+ free(latencyhist);
+ free(warmuphist);
+ free(type);
+ free(encoding);
+ free(inDevice);
+ free(outDevice);
+
+ return true;
+}
+
+};
diff --git a/services/mediaanalytics/statsd_audiotrack.cpp b/services/mediaanalytics/statsd_audiotrack.cpp
new file mode 100644
index 0000000..f250ced
--- /dev/null
+++ b/services/mediaanalytics/statsd_audiotrack.cpp
@@ -0,0 +1,156 @@
+/*
+ * Copyright (C) 2019 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 "statsd_audiotrack"
+#include <utils/Log.h>
+
+#include <dirent.h>
+#include <inttypes.h>
+#include <pthread.h>
+#include <pwd.h>
+#include <stdint.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <statslog.h>
+
+#include "MediaAnalyticsService.h"
+#include "frameworks/base/core/proto/android/stats/mediametrics/mediametrics.pb.h"
+#include "iface_statsd.h"
+
+namespace android {
+
+bool statsd_audiotrack(MediaAnalyticsItem *item)
+{
+ if (item == NULL) return false;
+
+ // these go into the statsd wrapper
+ nsecs_t timestamp = item->getTimestamp();
+ std::string pkgName = item->getPkgName();
+ int64_t pkgVersionCode = item->getPkgVersionCode();
+ int64_t mediaApexVersion = 0;
+
+
+ // the rest into our own proto
+ //
+ ::android::stats::mediametrics::AudioTrackData metrics_proto;
+
+ // flesh out the protobuf we'll hand off with our data
+ //
+
+ // static constexpr char kAudioTrackStreamType[] = "android.media.audiotrack.streamtype";
+ // optional string streamType;
+ char *streamtype = NULL;
+ if (item->getCString("android.media.audiotrack.streamtype", &streamtype)) {
+ metrics_proto.set_stream_type(streamtype);
+ }
+
+ // static constexpr char kAudioTrackContentType[] = "android.media.audiotrack.type";
+ // optional string contentType;
+ char *contenttype = NULL;
+ if (item->getCString("android.media.audiotrack.type", &contenttype)) {
+ metrics_proto.set_content_type(contenttype);
+ }
+
+ // static constexpr char kAudioTrackUsage[] = "android.media.audiotrack.usage";
+ // optional string trackUsage;
+ char *trackusage = NULL;
+ if (item->getCString("android.media.audiotrack.usage", &trackusage)) {
+ metrics_proto.set_track_usage(trackusage);
+ }
+
+ // static constexpr char kAudioTrackSampleRate[] = "android.media.audiotrack.samplerate";
+ // optional int32 samplerate;
+ int32_t samplerate = -1;
+ if (item->getInt32("android.media.audiotrack.samplerate", &samplerate)) {
+ metrics_proto.set_sample_rate(samplerate);
+ }
+
+ // static constexpr char kAudioTrackChannelMask[] = "android.media.audiotrack.channelmask";
+ // optional int64 channelMask;
+ int64_t channelMask = -1;
+ if (item->getInt64("android.media.audiotrack.channelmask", &channelMask)) {
+ metrics_proto.set_channel_mask(channelMask);
+ }
+
+ // NB: These are not yet exposed as public Java API constants.
+ // static constexpr char kAudioTrackUnderrunFrames[] = "android.media.audiotrack.underrunframes";
+ // optional int32 underrunframes;
+ int32_t underrunframes = -1;
+ if (item->getInt32("android.media.audiotrack.underrunframes", &underrunframes)) {
+ metrics_proto.set_underrun_frames(underrunframes);
+ }
+
+ // static constexpr char kAudioTrackStartupGlitch[] = "android.media.audiotrack.glitch.startup";
+ // optional int32 startupglitch;
+ int32_t startupglitch = -1;
+ if (item->getInt32("android.media.audiotrack.glitch.startup", &startupglitch)) {
+ metrics_proto.set_startup_glitch(startupglitch);
+ }
+
+ // portId (int32)
+ int32_t port_id = -1;
+ if (item->getInt32("android.media.audiotrack.portId", &port_id)) {
+ metrics_proto.set_port_id(port_id);
+ }
+ // encoding (string)
+ char *encoding = NULL;
+ if (item->getCString("android.media.audiotrack.encoding", &encoding)) {
+ metrics_proto.set_encoding(encoding);
+ }
+ // frameCount (int32)
+ int32_t frame_count = -1;
+ if (item->getInt32("android.media.audiotrack.frameCount", &frame_count)) {
+ metrics_proto.set_frame_count(frame_count);
+ }
+ // attributes (string)
+ char *attributes = NULL;
+ if (item->getCString("android.media.audiotrack.attributes", &attributes)) {
+ metrics_proto.set_attributes(attributes);
+ }
+
+ std::string serialized;
+ if (!metrics_proto.SerializeToString(&serialized)) {
+ ALOGE("Failed to serialize audiotrack metrics");
+ return false;
+ }
+
+ if (enabled_statsd) {
+ android::util::BytesField bf_serialized( serialized.c_str(), serialized.size());
+ (void)android::util::stats_write(android::util::MEDIAMETRICS_AUDIOTRACK_REPORTED,
+ timestamp, pkgName.c_str(), pkgVersionCode,
+ mediaApexVersion,
+ bf_serialized);
+
+ } else {
+ ALOGV("NOT sending: private data (len=%zu)", strlen(serialized.c_str()));
+ }
+
+ // must free the strings that we were given
+ free(streamtype);
+ free(contenttype);
+ free(trackusage);
+ free(encoding);
+ free(attributes);
+
+ return true;
+}
+
+};
diff --git a/services/mediaanalytics/statsd_codec.cpp b/services/mediaanalytics/statsd_codec.cpp
new file mode 100644
index 0000000..dc8e4ef
--- /dev/null
+++ b/services/mediaanalytics/statsd_codec.cpp
@@ -0,0 +1,185 @@
+/*
+ * Copyright (C) 2019 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 "statsd_codec"
+#include <utils/Log.h>
+
+#include <dirent.h>
+#include <inttypes.h>
+#include <pthread.h>
+#include <pwd.h>
+#include <stdint.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <statslog.h>
+
+#include "MediaAnalyticsService.h"
+#include "frameworks/base/core/proto/android/stats/mediametrics/mediametrics.pb.h"
+#include "iface_statsd.h"
+
+namespace android {
+
+bool statsd_codec(MediaAnalyticsItem *item)
+{
+ if (item == NULL) return false;
+
+ // these go into the statsd wrapper
+ nsecs_t timestamp = item->getTimestamp();
+ std::string pkgName = item->getPkgName();
+ int64_t pkgVersionCode = item->getPkgVersionCode();
+ int64_t mediaApexVersion = 0;
+
+
+ // the rest into our own proto
+ //
+ ::android::stats::mediametrics::CodecData metrics_proto;
+
+ // flesh out the protobuf we'll hand off with our data
+ //
+ // android.media.mediacodec.codec string
+ char *codec = NULL;
+ if (item->getCString("android.media.mediacodec.codec", &codec)) {
+ metrics_proto.set_codec(codec);
+ }
+ // android.media.mediacodec.mime string
+ char *mime = NULL;
+ if (item->getCString("android.media.mediacodec.mime", &mime)) {
+ metrics_proto.set_mime(mime);
+ }
+ // android.media.mediacodec.mode string
+ char *mode = NULL;
+ if ( item->getCString("android.media.mediacodec.mode", &mode)) {
+ metrics_proto.set_mode(mode);
+ }
+ // android.media.mediacodec.encoder int32
+ int32_t encoder = -1;
+ if ( item->getInt32("android.media.mediacodec.encoder", &encoder)) {
+ metrics_proto.set_encoder(encoder);
+ }
+ // android.media.mediacodec.secure int32
+ int32_t secure = -1;
+ if ( item->getInt32("android.media.mediacodec.secure", &secure)) {
+ metrics_proto.set_secure(secure);
+ }
+ // android.media.mediacodec.width int32
+ int32_t width = -1;
+ if ( item->getInt32("android.media.mediacodec.width", &width)) {
+ metrics_proto.set_width(width);
+ }
+ // android.media.mediacodec.height int32
+ int32_t height = -1;
+ if ( item->getInt32("android.media.mediacodec.height", &height)) {
+ metrics_proto.set_height(height);
+ }
+ // android.media.mediacodec.rotation-degrees int32
+ int32_t rotation = -1;
+ if ( item->getInt32("android.media.mediacodec.rotation-degrees", &rotation)) {
+ metrics_proto.set_rotation(rotation);
+ }
+ // android.media.mediacodec.crypto int32 (although missing if not needed
+ int32_t crypto = -1;
+ if ( item->getInt32("android.media.mediacodec.crypto", &crypto)) {
+ metrics_proto.set_crypto(crypto);
+ }
+ // android.media.mediacodec.profile int32
+ int32_t profile = -1;
+ if ( item->getInt32("android.media.mediacodec.profile", &profile)) {
+ metrics_proto.set_profile(profile);
+ }
+ // android.media.mediacodec.level int32
+ int32_t level = -1;
+ if ( item->getInt32("android.media.mediacodec.level", &level)) {
+ metrics_proto.set_level(level);
+ }
+ // android.media.mediacodec.maxwidth int32
+ int32_t maxwidth = -1;
+ if ( item->getInt32("android.media.mediacodec.maxwidth", &maxwidth)) {
+ metrics_proto.set_max_width(maxwidth);
+ }
+ // android.media.mediacodec.maxheight int32
+ int32_t maxheight = -1;
+ if ( item->getInt32("android.media.mediacodec.maxheight", &maxheight)) {
+ metrics_proto.set_max_height(maxheight);
+ }
+ // android.media.mediacodec.errcode int32
+ int32_t errcode = -1;
+ if ( item->getInt32("android.media.mediacodec.errcode", &errcode)) {
+ metrics_proto.set_error_code(errcode);
+ }
+ // android.media.mediacodec.errstate string
+ char *errstate = NULL;
+ if ( item->getCString("android.media.mediacodec.errstate", &errstate)) {
+ metrics_proto.set_error_state(errstate);
+ }
+ // android.media.mediacodec.latency.max int64
+ int64_t latency_max = -1;
+ if ( item->getInt64("android.media.mediacodec.latency.max", &latency_max)) {
+ metrics_proto.set_latency_max(latency_max);
+ }
+ // android.media.mediacodec.latency.min int64
+ int64_t latency_min = -1;
+ if ( item->getInt64("android.media.mediacodec.latency.min", &latency_min)) {
+ metrics_proto.set_latency_min(latency_min);
+ }
+ // android.media.mediacodec.latency.avg int64
+ int64_t latency_avg = -1;
+ if ( item->getInt64("android.media.mediacodec.latency.avg", &latency_avg)) {
+ metrics_proto.set_latency_avg(latency_avg);
+ }
+ // android.media.mediacodec.latency.n int64
+ int64_t latency_count = -1;
+ if ( item->getInt64("android.media.mediacodec.latency.n", &latency_count)) {
+ metrics_proto.set_latency_count(latency_count);
+ }
+ // android.media.mediacodec.latency.unknown int64
+ int64_t latency_unknown = -1;
+ if ( item->getInt64("android.media.mediacodec.latency.unknown", &latency_unknown)) {
+ metrics_proto.set_latency_unknown(latency_unknown);
+ }
+ // android.media.mediacodec.latency.hist NOT EMITTED
+
+ std::string serialized;
+ if (!metrics_proto.SerializeToString(&serialized)) {
+ ALOGE("Failed to serialize codec metrics");
+ return false;
+ }
+
+ if (enabled_statsd) {
+ android::util::BytesField bf_serialized( serialized.c_str(), serialized.size());
+ (void)android::util::stats_write(android::util::MEDIAMETRICS_CODEC_REPORTED,
+ timestamp, pkgName.c_str(), pkgVersionCode,
+ mediaApexVersion,
+ bf_serialized);
+
+ } else {
+ ALOGV("NOT sending: private data (len=%zu)", strlen(serialized.c_str()));
+ }
+
+ // must free the strings that we were given
+ free(codec);
+ free(mime);
+ free(mode);
+ free(errstate);
+
+ return true;
+}
+
+};
diff --git a/services/mediaanalytics/statsd_drm.cpp b/services/mediaanalytics/statsd_drm.cpp
new file mode 100644
index 0000000..902483a
--- /dev/null
+++ b/services/mediaanalytics/statsd_drm.cpp
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2019 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 "statsd_drm"
+#include <utils/Log.h>
+
+#include <stdint.h>
+#include <inttypes.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <dirent.h>
+#include <pthread.h>
+#include <unistd.h>
+
+#include <string.h>
+#include <pwd.h>
+
+#include "MediaAnalyticsService.h"
+#include "iface_statsd.h"
+
+#include <statslog.h>
+
+namespace android {
+
+// mediadrm
+bool statsd_mediadrm(MediaAnalyticsItem *item)
+{
+ if (item == NULL) return false;
+
+ nsecs_t timestamp = item->getTimestamp();
+ std::string pkgName = item->getPkgName();
+ int64_t pkgVersionCode = item->getPkgVersionCode();
+ int64_t mediaApexVersion = 0;
+
+ char *vendor = NULL;
+ (void) item->getCString("vendor", &vendor);
+ char *description = NULL;
+ (void) item->getCString("description", &description);
+ char *serialized_metrics = NULL;
+ (void) item->getCString("serialized_metrics", &serialized_metrics);
+
+ if (enabled_statsd) {
+ android::util::BytesField bf_serialized(serialized_metrics ? serialized_metrics : NULL,
+ serialized_metrics ? strlen(serialized_metrics)
+ : 0);
+ android::util::stats_write(android::util::MEDIAMETRICS_MEDIADRM_REPORTED,
+ timestamp, pkgName.c_str(), pkgVersionCode,
+ mediaApexVersion,
+ vendor, description,
+ bf_serialized);
+ } else {
+ ALOGV("NOT sending: mediadrm private data (len=%zu)",
+ serialized_metrics ? strlen(serialized_metrics) : 0);
+ }
+
+ free(vendor);
+ free(description);
+ free(serialized_metrics);
+ return true;
+}
+
+// widevineCDM
+bool statsd_widevineCDM(MediaAnalyticsItem *item)
+{
+ if (item == NULL) return false;
+
+ nsecs_t timestamp = item->getTimestamp();
+ std::string pkgName = item->getPkgName();
+ int64_t pkgVersionCode = item->getPkgVersionCode();
+ int64_t mediaApexVersion = 0;
+
+ char *serialized_metrics = NULL;
+ (void) item->getCString("serialized_metrics", &serialized_metrics);
+
+ if (enabled_statsd) {
+ android::util::BytesField bf_serialized(serialized_metrics ? serialized_metrics : NULL,
+ serialized_metrics ? strlen(serialized_metrics)
+ : 0);
+ android::util::stats_write(android::util::MEDIAMETRICS_DRM_WIDEVINE_REPORTED,
+ timestamp, pkgName.c_str(), pkgVersionCode,
+ mediaApexVersion,
+ bf_serialized);
+ } else {
+ ALOGV("NOT sending: widevine private data (len=%zu)",
+ serialized_metrics ? strlen(serialized_metrics) : 0);
+ }
+
+ free(serialized_metrics);
+ return true;
+}
+
+} // namespace android
diff --git a/services/mediaanalytics/statsd_extractor.cpp b/services/mediaanalytics/statsd_extractor.cpp
new file mode 100644
index 0000000..395c912
--- /dev/null
+++ b/services/mediaanalytics/statsd_extractor.cpp
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2019 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 "statsd_extractor"
+#include <utils/Log.h>
+
+#include <dirent.h>
+#include <inttypes.h>
+#include <pthread.h>
+#include <pwd.h>
+#include <stdint.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <statslog.h>
+
+#include "MediaAnalyticsService.h"
+#include "frameworks/base/core/proto/android/stats/mediametrics/mediametrics.pb.h"
+#include "iface_statsd.h"
+
+namespace android {
+
+bool statsd_extractor(MediaAnalyticsItem *item)
+{
+ if (item == NULL) return false;
+
+ // these go into the statsd wrapper
+ nsecs_t timestamp = item->getTimestamp();
+ std::string pkgName = item->getPkgName();
+ int64_t pkgVersionCode = item->getPkgVersionCode();
+ int64_t mediaApexVersion = 0;
+
+
+ // the rest into our own proto
+ //
+ ::android::stats::mediametrics::ExtractorData metrics_proto;
+
+ // flesh out the protobuf we'll hand off with our data
+ //
+
+ // android.media.mediaextractor.fmt string
+ char *fmt = NULL;
+ if (item->getCString("android.media.mediaextractor.fmt", &fmt)) {
+ metrics_proto.set_format(fmt);
+ }
+ // android.media.mediaextractor.mime string
+ char *mime = NULL;
+ if (item->getCString("android.media.mediaextractor.mime", &mime)) {
+ metrics_proto.set_mime(mime);
+ }
+ // android.media.mediaextractor.ntrk int32
+ int32_t ntrk = -1;
+ if (item->getInt32("android.media.mediaextractor.ntrk", &ntrk)) {
+ metrics_proto.set_tracks(ntrk);
+ }
+
+ std::string serialized;
+ if (!metrics_proto.SerializeToString(&serialized)) {
+ ALOGE("Failed to serialize extractor metrics");
+ return false;
+ }
+
+ if (enabled_statsd) {
+ android::util::BytesField bf_serialized( serialized.c_str(), serialized.size());
+ (void)android::util::stats_write(android::util::MEDIAMETRICS_EXTRACTOR_REPORTED,
+ timestamp, pkgName.c_str(), pkgVersionCode,
+ mediaApexVersion,
+ bf_serialized);
+
+ } else {
+ ALOGV("NOT sending: private data (len=%zu)", strlen(serialized.c_str()));
+ }
+
+ // must free the strings that we were given
+ free(fmt);
+ free(mime);
+
+ return true;
+}
+
+};
diff --git a/services/mediaanalytics/statsd_nuplayer.cpp b/services/mediaanalytics/statsd_nuplayer.cpp
new file mode 100644
index 0000000..5ec118a
--- /dev/null
+++ b/services/mediaanalytics/statsd_nuplayer.cpp
@@ -0,0 +1,178 @@
+/*
+ * Copyright (C) 2019 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 "statsd_nuplayer"
+#include <utils/Log.h>
+
+#include <dirent.h>
+#include <inttypes.h>
+#include <pthread.h>
+#include <pwd.h>
+#include <stdint.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <statslog.h>
+
+#include "MediaAnalyticsService.h"
+#include "frameworks/base/core/proto/android/stats/mediametrics/mediametrics.pb.h"
+#include "iface_statsd.h"
+
+namespace android {
+
+/*
+ * handles nuplayer AND nuplayer2
+ * checks for the union of what the two players generate
+ */
+bool statsd_nuplayer(MediaAnalyticsItem *item)
+{
+ if (item == NULL) return false;
+
+ // these go into the statsd wrapper
+ nsecs_t timestamp = item->getTimestamp();
+ std::string pkgName = item->getPkgName();
+ int64_t pkgVersionCode = item->getPkgVersionCode();
+ int64_t mediaApexVersion = 0;
+
+
+ // the rest into our own proto
+ //
+ ::android::stats::mediametrics::NuPlayerData metrics_proto;
+
+ // flesh out the protobuf we'll hand off with our data
+ //
+
+ // differentiate between nuplayer and nuplayer2
+ metrics_proto.set_whichplayer(item->getKey().c_str());
+
+ char *video_mime = NULL;
+ if (item->getCString("android.media.mediaplayer.video.mime", &video_mime)) {
+ metrics_proto.set_video_mime(video_mime);
+ }
+ char *video_codec = NULL;
+ if (item->getCString("android.media.mediaplayer.video.codec", &video_codec)) {
+ metrics_proto.set_video_codec(video_codec);
+ }
+
+ int32_t width = -1;
+ if (item->getInt32("android.media.mediaplayer.width", &width)) {
+ metrics_proto.set_width(width);
+ }
+ int32_t height = -1;
+ if (item->getInt32("android.media.mediaplayer.height", &height)) {
+ metrics_proto.set_height(height);
+ }
+
+ int64_t frames = -1;
+ if (item->getInt64("android.media.mediaplayer.frames", &frames)) {
+ metrics_proto.set_frames(frames);
+ }
+ int64_t frames_dropped = -1;
+ if (item->getInt64("android.media.mediaplayer.dropped", &frames_dropped)) {
+ metrics_proto.set_frames_dropped(frames_dropped);
+ }
+ int64_t frames_dropped_startup = -1;
+ if (item->getInt64("android.media.mediaplayer.startupdropped", &frames_dropped_startup)) {
+ metrics_proto.set_frames_dropped_startup(frames_dropped_startup);
+ }
+ double fps = -1.0;
+ if (item->getDouble("android.media.mediaplayer.fps", &fps)) {
+ metrics_proto.set_framerate(fps);
+ }
+
+ char *audio_mime = NULL;
+ if (item->getCString("android.media.mediaplayer.audio.mime", &audio_mime)) {
+ metrics_proto.set_audio_mime(audio_mime);
+ }
+ char *audio_codec = NULL;
+ if (item->getCString("android.media.mediaplayer.audio.codec", &audio_codec)) {
+ metrics_proto.set_audio_codec(audio_codec);
+ }
+
+ int64_t duration_ms = -1;
+ if (item->getInt64("android.media.mediaplayer.durationMs", &duration_ms)) {
+ metrics_proto.set_duration_millis(duration_ms);
+ }
+ int64_t playing_ms = -1;
+ if (item->getInt64("android.media.mediaplayer.playingMs", &playing_ms)) {
+ metrics_proto.set_playing_millis(playing_ms);
+ }
+
+ int32_t err = -1;
+ if (item->getInt32("android.media.mediaplayer.err", &err)) {
+ metrics_proto.set_error(err);
+ }
+ int32_t error_code = -1;
+ if (item->getInt32("android.media.mediaplayer.errcode", &error_code)) {
+ metrics_proto.set_error_code(error_code);
+ }
+ char *error_state = NULL;
+ if (item->getCString("android.media.mediaplayer.errstate", &error_state)) {
+ metrics_proto.set_error_state(error_state);
+ }
+
+ char *data_source_type = NULL;
+ if (item->getCString("android.media.mediaplayer.dataSource", &data_source_type)) {
+ metrics_proto.set_data_source_type(data_source_type);
+ }
+
+ int64_t rebufferingMs = -1;
+ if (item->getInt64("android.media.mediaplayer.rebufferingMs", &rebufferingMs)) {
+ metrics_proto.set_rebuffering_millis(rebufferingMs);
+ }
+ int32_t rebuffers = -1;
+ if (item->getInt32("android.media.mediaplayer.rebuffers", &rebuffers)) {
+ metrics_proto.set_rebuffers(rebuffers);
+ }
+ int32_t rebufferExit = -1;
+ if (item->getInt32("android.media.mediaplayer.rebufferExit", &rebufferExit)) {
+ metrics_proto.set_rebuffer_at_exit(rebufferExit);
+ }
+
+
+ std::string serialized;
+ if (!metrics_proto.SerializeToString(&serialized)) {
+ ALOGE("Failed to serialize nuplayer metrics");
+ return false;
+ }
+
+ if (enabled_statsd) {
+ android::util::BytesField bf_serialized( serialized.c_str(), serialized.size());
+ (void)android::util::stats_write(android::util::MEDIAMETRICS_NUPLAYER_REPORTED,
+ timestamp, pkgName.c_str(), pkgVersionCode,
+ mediaApexVersion,
+ bf_serialized);
+
+ } else {
+ ALOGV("NOT sending: private data (len=%zu)", strlen(serialized.c_str()));
+ }
+
+ // must free the strings that we were given
+ free(video_mime);
+ free(video_codec);
+ free(audio_mime);
+ free(audio_codec);
+ free(error_state);
+ free(data_source_type);
+
+ return true;
+}
+
+};
diff --git a/services/mediaanalytics/statsd_recorder.cpp b/services/mediaanalytics/statsd_recorder.cpp
new file mode 100644
index 0000000..4d981b4
--- /dev/null
+++ b/services/mediaanalytics/statsd_recorder.cpp
@@ -0,0 +1,193 @@
+/*
+ * Copyright (C) 2019 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 "statsd_recorder"
+#include <utils/Log.h>
+
+#include <dirent.h>
+#include <inttypes.h>
+#include <pthread.h>
+#include <pwd.h>
+#include <stdint.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <statslog.h>
+
+#include "MediaAnalyticsService.h"
+#include "frameworks/base/core/proto/android/stats/mediametrics/mediametrics.pb.h"
+#include "iface_statsd.h"
+
+namespace android {
+
+bool statsd_recorder(MediaAnalyticsItem *item)
+{
+ if (item == NULL) return false;
+
+ // these go into the statsd wrapper
+ nsecs_t timestamp = item->getTimestamp();
+ std::string pkgName = item->getPkgName();
+ int64_t pkgVersionCode = item->getPkgVersionCode();
+ int64_t mediaApexVersion = 0;
+
+
+ // the rest into our own proto
+ //
+ ::android::stats::mediametrics::RecorderData metrics_proto;
+
+ // flesh out the protobuf we'll hand off with our data
+ //
+
+ // string kRecorderAudioMime = "android.media.mediarecorder.audio.mime";
+ char *audio_mime = NULL;
+ if (item->getCString("android.media.mediarecorder.audio.mime", &audio_mime)) {
+ metrics_proto.set_audio_mime(audio_mime);
+ }
+ // string kRecorderVideoMime = "android.media.mediarecorder.video.mime";
+ char *video_mime = NULL;
+ if (item->getCString("android.media.mediarecorder.video.mime", &video_mime)) {
+ metrics_proto.set_video_mime(video_mime);
+ }
+ // int32 kRecorderVideoProfile = "android.media.mediarecorder.video-encoder-profile";
+ int32_t videoProfile = -1;
+ if (item->getInt32("android.media.mediarecorder.video-encoder-profile", &videoProfile)) {
+ metrics_proto.set_video_profile(videoProfile);
+ }
+ // int32 kRecorderVideoLevel = "android.media.mediarecorder.video-encoder-level";
+ int32_t videoLevel = -1;
+ if (item->getInt32("android.media.mediarecorder.video-encoder-level", &videoLevel)) {
+ metrics_proto.set_video_level(videoLevel);
+ }
+ // int32 kRecorderWidth = "android.media.mediarecorder.width";
+ int32_t width = -1;
+ if (item->getInt32("android.media.mediarecorder.width", &width)) {
+ metrics_proto.set_width(width);
+ }
+ // int32 kRecorderHeight = "android.media.mediarecorder.height";
+ int32_t height = -1;
+ if (item->getInt32("android.media.mediarecorder.height", &height)) {
+ metrics_proto.set_height(height);
+ }
+ // int32 kRecorderRotation = "android.media.mediarecorder.rotation";
+ int32_t rotation = -1; // default to 0?
+ if (item->getInt32("android.media.mediarecorder.rotation", &rotation)) {
+ metrics_proto.set_rotation(rotation);
+ }
+ // int32 kRecorderFrameRate = "android.media.mediarecorder.frame-rate";
+ int32_t framerate = -1;
+ if (item->getInt32("android.media.mediarecorder.frame-rate", &framerate)) {
+ metrics_proto.set_framerate(framerate);
+ }
+
+ // int32 kRecorderCaptureFps = "android.media.mediarecorder.capture-fps";
+ int32_t captureFps = -1;
+ if (item->getInt32("android.media.mediarecorder.capture-fps", &captureFps)) {
+ metrics_proto.set_capture_fps(captureFps);
+ }
+ // double kRecorderCaptureFpsEnable = "android.media.mediarecorder.capture-fpsenable";
+ double captureFpsEnable = -1;
+ if (item->getDouble("android.media.mediarecorder.capture-fpsenable", &captureFpsEnable)) {
+ metrics_proto.set_capture_fps_enable(captureFpsEnable);
+ }
+
+ // int64 kRecorderDurationMs = "android.media.mediarecorder.durationMs";
+ int64_t durationMs = -1;
+ if (item->getInt64("android.media.mediarecorder.durationMs", &durationMs)) {
+ metrics_proto.set_duration_millis(durationMs);
+ }
+ // int64 kRecorderPaused = "android.media.mediarecorder.pausedMs";
+ int64_t pausedMs = -1;
+ if (item->getInt64("android.media.mediarecorder.pausedMs", &pausedMs)) {
+ metrics_proto.set_paused_millis(pausedMs);
+ }
+ // int32 kRecorderNumPauses = "android.media.mediarecorder.NPauses";
+ int32_t pausedCount = -1;
+ if (item->getInt32("android.media.mediarecorder.NPauses", &pausedCount)) {
+ metrics_proto.set_paused_count(pausedCount);
+ }
+
+ // int32 kRecorderAudioBitrate = "android.media.mediarecorder.audio-bitrate";
+ int32_t audioBitrate = -1;
+ if (item->getInt32("android.media.mediarecorder.audio-bitrate", &audioBitrate)) {
+ metrics_proto.set_audio_bitrate(audioBitrate);
+ }
+ // int32 kRecorderAudioChannels = "android.media.mediarecorder.audio-channels";
+ int32_t audioChannels = -1;
+ if (item->getInt32("android.media.mediarecorder.audio-channels", &audioChannels)) {
+ metrics_proto.set_audio_channels(audioChannels);
+ }
+ // int32 kRecorderAudioSampleRate = "android.media.mediarecorder.audio-samplerate";
+ int32_t audioSampleRate = -1;
+ if (item->getInt32("android.media.mediarecorder.audio-samplerate", &audioSampleRate)) {
+ metrics_proto.set_audio_samplerate(audioSampleRate);
+ }
+
+ // int32 kRecorderMovieTimescale = "android.media.mediarecorder.movie-timescale";
+ int32_t movieTimescale = -1;
+ if (item->getInt32("android.media.mediarecorder.movie-timescale", &movieTimescale)) {
+ metrics_proto.set_movie_timescale(movieTimescale);
+ }
+ // int32 kRecorderAudioTimescale = "android.media.mediarecorder.audio-timescale";
+ int32_t audioTimescale = -1;
+ if (item->getInt32("android.media.mediarecorder.audio-timescale", &audioTimescale)) {
+ metrics_proto.set_audio_timescale(audioTimescale);
+ }
+ // int32 kRecorderVideoTimescale = "android.media.mediarecorder.video-timescale";
+ int32_t videoTimescale = -1;
+ if (item->getInt32("android.media.mediarecorder.video-timescale", &videoTimescale)) {
+ metrics_proto.set_video_timescale(videoTimescale);
+ }
+
+ // int32 kRecorderVideoBitrate = "android.media.mediarecorder.video-bitrate";
+ int32_t videoBitRate = -1;
+ if (item->getInt32("android.media.mediarecorder.video-bitrate", &videoBitRate)) {
+ metrics_proto.set_video_bitrate(videoBitRate);
+ }
+ // int32 kRecorderVideoIframeInterval = "android.media.mediarecorder.video-iframe-interval";
+ int32_t iFrameInterval = -1;
+ if (item->getInt32("android.media.mediarecorder.video-iframe-interval", &iFrameInterval)) {
+ metrics_proto.set_iframe_interval(iFrameInterval);
+ }
+
+ std::string serialized;
+ if (!metrics_proto.SerializeToString(&serialized)) {
+ ALOGE("Failed to serialize recorder metrics");
+ return false;
+ }
+
+ if (enabled_statsd) {
+ android::util::BytesField bf_serialized( serialized.c_str(), serialized.size());
+ (void)android::util::stats_write(android::util::MEDIAMETRICS_RECORDER_REPORTED,
+ timestamp, pkgName.c_str(), pkgVersionCode,
+ mediaApexVersion,
+ bf_serialized);
+
+ } else {
+ ALOGV("NOT sending: private data (len=%zu)", strlen(serialized.c_str()));
+ }
+
+ // must free the strings that we were given
+ free(audio_mime);
+ free(video_mime);
+
+ return true;
+}
+
+};
diff --git a/services/mediacodec/Android.mk b/services/mediacodec/Android.mk
index 473e21c..ecd437b 100644
--- a/services/mediacodec/Android.mk
+++ b/services/mediacodec/Android.mk
@@ -22,6 +22,7 @@
libstagefright_soft_vorbisdec \
libstagefright_soft_vpxdec \
libstagefright_soft_vpxenc \
+ libstagefright_softomx_plugin \
# service executable
include $(CLEAR_VARS)
diff --git a/services/mediaextractor/MediaExtractorService.cpp b/services/mediaextractor/MediaExtractorService.cpp
index de5c3e4..36e084b 100644
--- a/services/mediaextractor/MediaExtractorService.cpp
+++ b/services/mediaextractor/MediaExtractorService.cpp
@@ -30,7 +30,9 @@
namespace android {
MediaExtractorService::MediaExtractorService()
- : BnMediaExtractorService() { }
+ : BnMediaExtractorService() {
+ MediaExtractorFactory::LoadExtractors();
+}
sp<IMediaExtractor> MediaExtractorService::makeExtractor(
const sp<IDataSource> &remoteSource, const char *mime) {