diff options
author | Narayan Kamath <narayan@google.com> | 2011-11-16 15:57:29 +0000 |
---|---|---|
committer | Narayan Kamath <narayan@google.com> | 2011-12-06 17:31:39 +0000 |
commit | 6c83e3be2921009ff7dcfced2a3eda7811b8b041 (patch) | |
tree | 9d54b94b6a9b0fcfb456ae05e21953e8ea97d9f0 /media/libstagefright/chromium_http | |
parent | 2013d4d159bfc29b4143d3b5fd4735f51a03684c (diff) | |
download | frameworks_av-6c83e3be2921009ff7dcfced2a3eda7811b8b041.zip frameworks_av-6c83e3be2921009ff7dcfced2a3eda7811b8b041.tar.gz frameworks_av-6c83e3be2921009ff7dcfced2a3eda7811b8b041.tar.bz2 |
Allow data uris to be data sources
bug:5571010
Change-Id: I0b6ae6c729ac34d46e9990fcceb08294eb4f7c58
Diffstat (limited to 'media/libstagefright/chromium_http')
-rw-r--r-- | media/libstagefright/chromium_http/Android.mk | 5 | ||||
-rw-r--r-- | media/libstagefright/chromium_http/DataUriSource.cpp | 68 |
2 files changed, 71 insertions, 2 deletions
diff --git a/media/libstagefright/chromium_http/Android.mk b/media/libstagefright/chromium_http/Android.mk index 6573e3c..63775f1 100644 --- a/media/libstagefright/chromium_http/Android.mk +++ b/media/libstagefright/chromium_http/Android.mk @@ -3,8 +3,9 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ - ChromiumHTTPDataSource.cpp \ - support.cpp \ + DataUriSource.cpp \ + ChromiumHTTPDataSource.cpp \ + support.cpp LOCAL_C_INCLUDES:= \ $(JNI_H_INCLUDE) \ diff --git a/media/libstagefright/chromium_http/DataUriSource.cpp b/media/libstagefright/chromium_http/DataUriSource.cpp new file mode 100644 index 0000000..ecf3fa1 --- /dev/null +++ b/media/libstagefright/chromium_http/DataUriSource.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2011 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. + */ + +#include <include/DataUriSource.h> + +#include <net/base/data_url.h> +#include <googleurl/src/gurl.h> + + +namespace android { + +DataUriSource::DataUriSource(const char *uri) : + mDataUri(uri), + mInited(NO_INIT) { + + // Copy1: const char *uri -> String8 mDataUri. + std::string mimeTypeStr, unusedCharsetStr, dataStr; + // Copy2: String8 mDataUri -> std::string + const bool ret = net::DataURL::Parse( + GURL(std::string(mDataUri.string())), + &mimeTypeStr, &unusedCharsetStr, &dataStr); + // Copy3: std::string dataStr -> AString mData + mData.setTo(dataStr.data(), dataStr.length()); + mInited = ret ? OK : UNKNOWN_ERROR; + + // The chromium data url implementation defaults to using "text/plain" + // if no mime type is specified. We prefer to leave this unspecified + // instead, since the mime type is sniffed in most cases. + if (mimeTypeStr != "text/plain") { + mMimeType = mimeTypeStr.c_str(); + } +} + +ssize_t DataUriSource::readAt(off64_t offset, void *out, size_t size) { + if (mInited != OK) { + return mInited; + } + + const off64_t length = mData.size(); + if (offset >= length) { + return UNKNOWN_ERROR; + } + + const char *dataBuf = mData.c_str(); + const size_t bytesToCopy = + offset + size >= length ? (length - offset) : size; + + if (bytesToCopy > 0) { + memcpy(out, dataBuf + offset, bytesToCopy); + } + + return bytesToCopy; +} + +} // namespace android |