diff options
author | Glenn Kasten <gkasten@google.com> | 2013-01-18 15:31:41 -0800 |
---|---|---|
committer | Glenn Kasten <gkasten@google.com> | 2013-01-25 15:12:14 -0800 |
commit | 6f1c1918d0dfece10f728711b055441e4d135c73 (patch) | |
tree | e82c0166e895f9c61c11ff0800d2871298e63b30 /services | |
parent | 11d8dfcc063425ae7d59229f54b6752fd8987c10 (diff) | |
download | frameworks_av-6f1c1918d0dfece10f728711b055441e4d135c73.zip frameworks_av-6f1c1918d0dfece10f728711b055441e4d135c73.tar.gz frameworks_av-6f1c1918d0dfece10f728711b055441e4d135c73.tar.bz2 |
Add media.log service based on NBLog
Change-Id: Ie45093df6ac9a739d05c8d408fab52a9a8a27e7f
Diffstat (limited to 'services')
-rw-r--r-- | services/medialog/Android.mk | 11 | ||||
-rw-r--r-- | services/medialog/MediaLogService.cpp | 81 | ||||
-rw-r--r-- | services/medialog/MediaLogService.h | 65 |
3 files changed, 157 insertions, 0 deletions
diff --git a/services/medialog/Android.mk b/services/medialog/Android.mk new file mode 100644 index 0000000..559b1ed --- /dev/null +++ b/services/medialog/Android.mk @@ -0,0 +1,11 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := MediaLogService.cpp + +LOCAL_SHARED_LIBRARIES := libmedia libbinder libutils libnbaio + +LOCAL_MODULE:= libmedialogservice + +include $(BUILD_SHARED_LIBRARY) diff --git a/services/medialog/MediaLogService.cpp b/services/medialog/MediaLogService.cpp new file mode 100644 index 0000000..2332b3e --- /dev/null +++ b/services/medialog/MediaLogService.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2013 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_TAG "MediaLog" +//#define LOG_NDEBUG 0 + +#include <sys/mman.h> +#include <utils/Log.h> +#include <media/nbaio/NBLog.h> +#include <private/android_filesystem_config.h> +#include "MediaLogService.h" + +namespace android { + +void MediaLogService::registerWriter(const sp<IMemory>& shared, size_t size, const char *name) +{ + if (IPCThreadState::self()->getCallingUid() != AID_MEDIA || shared == 0 || + size < kMinSize || size > kMaxSize || name == NULL || + shared->size() < NBLog::Timeline::sharedSize(size)) { + return; + } + sp<NBLog::Reader> reader(new NBLog::Reader(size, shared)); + NamedReader namedReader(reader, name); + Mutex::Autolock _l(mLock); + mNamedReaders.add(namedReader); +} + +void MediaLogService::unregisterWriter(const sp<IMemory>& shared) +{ + if (IPCThreadState::self()->getCallingUid() != AID_MEDIA || shared == 0) { + return; + } + Mutex::Autolock _l(mLock); + for (size_t i = 0; i < mNamedReaders.size(); ) { + if (mNamedReaders[i].reader()->isIMemory(shared)) { + mNamedReaders.removeAt(i); + } else { + i++; + } + } +} + +status_t MediaLogService::dump(int fd, const Vector<String16>& args) +{ + Vector<NamedReader> namedReaders; + { + Mutex::Autolock _l(mLock); + namedReaders = mNamedReaders; + } + for (size_t i = 0; i < namedReaders.size(); i++) { + const NamedReader& namedReader = namedReaders[i]; + if (fd >= 0) { + fdprintf(fd, "\n%s:\n", namedReader.name()); + } else { + ALOGI("%s:", namedReader.name()); + } + namedReader.reader()->dump(fd, 0 /*indent*/); + } + return NO_ERROR; +} + +status_t MediaLogService::onTransact(uint32_t code, const Parcel& data, Parcel* reply, + uint32_t flags) +{ + return BnMediaLogService::onTransact(code, data, reply, flags); +} + +} // namespace android diff --git a/services/medialog/MediaLogService.h b/services/medialog/MediaLogService.h new file mode 100644 index 0000000..2d89a41 --- /dev/null +++ b/services/medialog/MediaLogService.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2013 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 ANDROID_MEDIA_LOG_SERVICE_H +#define ANDROID_MEDIA_LOG_SERVICE_H + +#include <binder/BinderService.h> +#include <media/IMediaLogService.h> +#include <media/nbaio/NBLog.h> + +namespace android { + +class MediaLogService : public BinderService<MediaLogService>, public BnMediaLogService +{ + friend class BinderService<MediaLogService>; // for MediaLogService() +public: + MediaLogService() : BnMediaLogService() { } + virtual ~MediaLogService() { } + virtual void onFirstRef() { } + + static const char* getServiceName() { return "media.log"; } + + static const size_t kMinSize = 0x100; + static const size_t kMaxSize = 0x10000; + virtual void registerWriter(const sp<IMemory>& shared, size_t size, const char *name); + virtual void unregisterWriter(const sp<IMemory>& shared); + + virtual status_t dump(int fd, const Vector<String16>& args); + virtual status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, + uint32_t flags); + +private: + Mutex mLock; + class NamedReader { + public: + NamedReader() : mReader(0) { mName[0] = '\0'; } // for Vector + NamedReader(const sp<NBLog::Reader>& reader, const char *name) : mReader(reader) + { strlcpy(mName, name, sizeof(mName)); } + ~NamedReader() { } + const sp<NBLog::Reader>& reader() const { return mReader; } + const char* name() const { return mName; } + private: + sp<NBLog::Reader> mReader; + static const size_t kMaxName = 32; + char mName[kMaxName]; + }; + Vector<NamedReader> mNamedReaders; +}; + +} // namespace android + +#endif // ANDROID_MEDIA_LOG_SERVICE_H |