diff options
Diffstat (limited to 'media')
78 files changed, 636 insertions, 1481 deletions
diff --git a/media/java/android/media/MtpClient.java b/media/java/android/media/MtpClient.java index 98da1f6..dcb1983 100644 --- a/media/java/android/media/MtpClient.java +++ b/media/java/android/media/MtpClient.java @@ -16,7 +16,6 @@ package android.media; -import android.os.ParcelFileDescriptor; import android.util.Log; /** @@ -69,9 +68,10 @@ public class MtpClient { return native_get_storage_id(deviceID, objectID); } - // create a file descriptor for reading the contents of an object over MTP - public ParcelFileDescriptor openFile(int deviceID, long objectID) { - return native_open_file(deviceID, objectID); + // Reads a file from device to host to the specified destination. + // Returns true if the transfer succeeds. + public boolean importFile(int deviceID, long objectID, String destPath) { + return native_import_file(deviceID, objectID, destPath); } public interface Listener { @@ -104,5 +104,5 @@ public class MtpClient { private native boolean native_delete_object(int deviceID, long objectID); private native long native_get_parent(int deviceID, long objectID); private native long native_get_storage_id(int deviceID, long objectID); - private native ParcelFileDescriptor native_open_file(int deviceID, long objectID); + private native boolean native_import_file(int deviceID, long objectID, String destPath); } diff --git a/media/java/android/media/MtpCursor.java b/media/java/android/media/MtpCursor.java index 9b5ab95..daa3f4d 100644 --- a/media/java/android/media/MtpCursor.java +++ b/media/java/android/media/MtpCursor.java @@ -40,6 +40,7 @@ public final class MtpCursor extends AbstractWindowedCursor { public static final int OBJECT_ID = 6; public static final int STORAGE_CHILDREN = 7; public static final int OBJECT_CHILDREN = 8; + public static final int OBJECT_IMPORT = 9; /** The names of the columns in the projection */ private String[] mColumns; diff --git a/media/java/android/media/videoeditor/AudioTrack.java b/media/java/android/media/videoeditor/AudioTrack.java index cf7a25c..e95ef35 100755 --- a/media/java/android/media/videoeditor/AudioTrack.java +++ b/media/java/android/media/videoeditor/AudioTrack.java @@ -286,9 +286,7 @@ public class AudioTrack { }
/**
- * @return The timeline duration. If looping is enabled this value
- * represents the duration of the looped audio track, otherwise it
- * is the duration of the audio track (mDurationMs).
+ * @return The timeline duration as defined by the begin and end boundaries
*/
public long getTimelineDuration() {
return mTimelineDurationMs;
@@ -312,13 +310,8 @@ public class AudioTrack { mBeginBoundaryTimeMs = beginMs;
mEndBoundaryTimeMs = endMs;
- if (mLoop) {
- // TODO: Compute mDurationMs (from the beginning of the loop until
- // the end of all the loops.
- mTimelineDurationMs = mEndBoundaryTimeMs - mBeginBoundaryTimeMs;
- } else {
- mTimelineDurationMs = mEndBoundaryTimeMs - mBeginBoundaryTimeMs;
- }
+
+ mTimelineDurationMs = mEndBoundaryTimeMs - mBeginBoundaryTimeMs;
}
/**
diff --git a/media/jni/android_media_MtpClient.cpp b/media/jni/android_media_MtpClient.cpp index d23185b..144dfc8 100644 --- a/media/jni/android_media_MtpClient.cpp +++ b/media/jni/android_media_MtpClient.cpp @@ -26,6 +26,7 @@ #include "jni.h" #include "JNIHelp.h" #include "android_runtime/AndroidRuntime.h" +#include "private/android_filesystem_config.h" #include "MtpClient.h" #include "MtpDevice.h" @@ -39,19 +40,6 @@ static jmethodID method_deviceAdded; static jmethodID method_deviceRemoved; static jfieldID field_context; -static struct file_descriptor_offsets_t -{ - jclass mClass; - jmethodID mConstructor; - jfieldID mDescriptor; -} gFileDescriptorOffsets; - -static struct parcel_file_descriptor_offsets_t -{ - jclass mClass; - jmethodID mConstructor; -} gParcelFileDescriptorOffsets; - #ifdef HAVE_ANDROID_OS static void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) { @@ -201,34 +189,19 @@ android_media_MtpClient_get_storage_id(JNIEnv *env, jobject thiz, return -1; } -static jobject -android_media_MtpClient_open_file(JNIEnv *env, jobject thiz, - jint device_id, jlong object_id) +static jboolean +android_media_MtpClient_import_file(JNIEnv *env, jobject thiz, + jint device_id, jlong object_id, jstring dest_path) { #ifdef HAVE_ANDROID_OS MyClient *client = (MyClient *)env->GetIntField(thiz, field_context); MtpDevice* device = client->getDevice(device_id); - if (!device) - return NULL; - - MtpObjectInfo* info = device->getObjectInfo(object_id); - if (!info) - return NULL; - int object_size = info->mCompressedSize; - delete info; - int fd = device->readObject(object_id, object_size); - if (fd < 0) - return NULL; - - jobject fileDescriptor = env->NewObject(gFileDescriptorOffsets.mClass, - gFileDescriptorOffsets.mConstructor); - if (fileDescriptor != NULL) { - env->SetIntField(fileDescriptor, gFileDescriptorOffsets.mDescriptor, fd); - } else { - return NULL; + if (device) { + const char *destPathStr = env->GetStringUTFChars(dest_path, NULL); + bool result = device->readObject(object_id, destPathStr, AID_SDCARD_RW, 0664); + env->ReleaseStringUTFChars(dest_path, destPathStr); + return result; } - return env->NewObject(gParcelFileDescriptorOffsets.mClass, - gParcelFileDescriptorOffsets.mConstructor, fileDescriptor); #endif return NULL; } @@ -243,8 +216,8 @@ static JNINativeMethod gMethods[] = { {"native_delete_object", "(IJ)Z", (void *)android_media_MtpClient_delete_object}, {"native_get_parent", "(IJ)J", (void *)android_media_MtpClient_get_parent}, {"native_get_storage_id", "(IJ)J", (void *)android_media_MtpClient_get_storage_id}, - {"native_open_file", "(IJ)Landroid/os/ParcelFileDescriptor;", - (void *)android_media_MtpClient_open_file}, + {"native_import_file", "(IJLjava/lang/String;)Z", + (void *)android_media_MtpClient_import_file}, }; static const char* const kClassPathName = "android/media/MtpClient"; @@ -276,21 +249,6 @@ int register_android_media_MtpClient(JNIEnv *env) return -1; } - clazz = env->FindClass("java/io/FileDescriptor"); - LOG_FATAL_IF(clazz == NULL, "Unable to find class java.io.FileDescriptor"); - gFileDescriptorOffsets.mClass = (jclass) env->NewGlobalRef(clazz); - gFileDescriptorOffsets.mConstructor = env->GetMethodID(clazz, "<init>", "()V"); - gFileDescriptorOffsets.mDescriptor = env->GetFieldID(clazz, "descriptor", "I"); - LOG_FATAL_IF(gFileDescriptorOffsets.mDescriptor == NULL, - "Unable to find descriptor field in java.io.FileDescriptor"); - - clazz = env->FindClass("android/os/ParcelFileDescriptor"); - LOG_FATAL_IF(clazz == NULL, "Unable to find class android.os.ParcelFileDescriptor"); - gParcelFileDescriptorOffsets.mClass = (jclass) env->NewGlobalRef(clazz); - gParcelFileDescriptorOffsets.mConstructor = env->GetMethodID(clazz, "<init>", "(Ljava/io/FileDescriptor;)V"); - LOG_FATAL_IF(gParcelFileDescriptorOffsets.mConstructor == NULL, - "Unable to find constructor for android.os.ParcelFileDescriptor"); - return AndroidRuntime::registerNativeMethods(env, "android/media/MtpClient", gMethods, NELEM(gMethods)); } diff --git a/media/jni/soundpool/SoundPool.h b/media/jni/soundpool/SoundPool.h index 42037af..1b0fd38 100644 --- a/media/jni/soundpool/SoundPool.h +++ b/media/jni/soundpool/SoundPool.h @@ -22,7 +22,6 @@ #include <utils/Vector.h> #include <utils/KeyedVector.h> #include <media/AudioTrack.h> -#include <cutils/atomic.h> namespace android { diff --git a/media/libmedia/AudioEffect.cpp b/media/libmedia/AudioEffect.cpp index 88b8c86..aadeba5 100644 --- a/media/libmedia/AudioEffect.cpp +++ b/media/libmedia/AudioEffect.cpp @@ -27,7 +27,6 @@ #include <media/AudioEffect.h> #include <utils/Log.h> -#include <cutils/atomic.h> #include <binder/IPCThreadState.h> @@ -207,18 +206,22 @@ status_t AudioEffect::setEnabled(bool enabled) return INVALID_OPERATION; } - if (enabled) { - LOGV("enable %p", this); - if (android_atomic_or(1, &mEnabled) == 0) { - return mIEffect->enable(); + status_t status = NO_ERROR; + + AutoMutex lock(mLock); + if (enabled != mEnabled) { + if (enabled) { + LOGV("enable %p", this); + status = mIEffect->enable(); + } else { + LOGV("disable %p", this); + status = mIEffect->disable(); } - } else { - LOGV("disable %p", this); - if (android_atomic_and(~1, &mEnabled) == 1) { - return mIEffect->disable(); + if (status == NO_ERROR) { + mEnabled = enabled; } } - return NO_ERROR; + return status; } status_t AudioEffect::command(uint32_t cmdCode, @@ -232,26 +235,26 @@ status_t AudioEffect::command(uint32_t cmdCode, return INVALID_OPERATION; } - if ((cmdCode == EFFECT_CMD_ENABLE || cmdCode == EFFECT_CMD_DISABLE) && - (replySize == NULL || *replySize != sizeof(status_t) || replyData == NULL)) { - return BAD_VALUE; + if (cmdCode == EFFECT_CMD_ENABLE || cmdCode == EFFECT_CMD_DISABLE) { + if (mEnabled == (cmdCode == EFFECT_CMD_ENABLE)) { + return NO_ERROR; + } + if (replySize == NULL || *replySize != sizeof(status_t) || replyData == NULL) { + return BAD_VALUE; + } + mLock.lock(); } status_t status = mIEffect->command(cmdCode, cmdSize, cmdData, replySize, replyData); - if (status != NO_ERROR) { - return status; - } if (cmdCode == EFFECT_CMD_ENABLE || cmdCode == EFFECT_CMD_DISABLE) { - status = *(status_t *)replyData; - if (status != NO_ERROR) { - return status; + if (status == NO_ERROR) { + status = *(status_t *)replyData; } - if (cmdCode == EFFECT_CMD_ENABLE) { - android_atomic_or(1, &mEnabled); - } else { - android_atomic_and(~1, &mEnabled); + if (status == NO_ERROR) { + mEnabled = (cmdCode == EFFECT_CMD_ENABLE); } + mLock.unlock(); } return status; @@ -370,11 +373,7 @@ void AudioEffect::enableStatusChanged(bool enabled) { LOGV("enableStatusChanged %p enabled %d mCbf %p", this, enabled, mCbf); if (mStatus == ALREADY_EXISTS) { - if (enabled) { - android_atomic_or(1, &mEnabled); - } else { - android_atomic_and(~1, &mEnabled); - } + mEnabled = enabled; if (mCbf) { mCbf(EVENT_ENABLE_STATUS_CHANGED, mUserData, &enabled); } diff --git a/media/libmedia/AudioRecord.cpp b/media/libmedia/AudioRecord.cpp index a6c515c..1d6ffa0 100644 --- a/media/libmedia/AudioRecord.cpp +++ b/media/libmedia/AudioRecord.cpp @@ -35,7 +35,6 @@ #include <binder/Parcel.h> #include <binder/IPCThreadState.h> #include <utils/Timers.h> -#include <cutils/atomic.h> #define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) #define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) @@ -282,7 +281,9 @@ status_t AudioRecord::start() t->mLock.lock(); } - if (android_atomic_or(1, &mActive) == 0) { + AutoMutex lock(mLock); + if (mActive == 0) { + mActive = 1; ret = mAudioRecord->start(); if (ret == DEAD_OBJECT) { LOGV("start() dead IAudioRecord: creating a new one"); @@ -302,8 +303,7 @@ status_t AudioRecord::start() setpriority(PRIO_PROCESS, 0, THREAD_PRIORITY_AUDIO_CLIENT); } } else { - LOGV("start() failed"); - android_atomic_and(~1, &mActive); + mActive = 0; } } @@ -322,9 +322,11 @@ status_t AudioRecord::stop() if (t != 0) { t->mLock.lock(); - } + } - if (android_atomic_and(~1, &mActive) == 1) { + AutoMutex lock(mLock); + if (mActive == 1) { + mActive = 0; mCblk->cv.signal(); mAudioRecord->stop(); // the record head position will reset to 0, so if a marker is set, we need diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp index 587c8ff..c1bed59 100644 --- a/media/libmedia/AudioTrack.cpp +++ b/media/libmedia/AudioTrack.cpp @@ -35,7 +35,6 @@ #include <binder/Parcel.h> #include <binder/IPCThreadState.h> #include <utils/Timers.h> -#include <cutils/atomic.h> #define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) #define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) @@ -312,7 +311,9 @@ void AudioTrack::start() t->mLock.lock(); } - if (android_atomic_or(1, &mActive) == 0) { + AutoMutex lock(mLock); + if (mActive == 0) { + mActive = 1; mNewPosition = mCblk->server + mUpdatePeriod; mCblk->bufferTimeoutMs = MAX_STARTUP_TIMEOUT_MS; mCblk->waitTimeMs = 0; @@ -344,7 +345,7 @@ void AudioTrack::start() } if (status != NO_ERROR) { LOGV("start() failed"); - android_atomic_and(~1, &mActive); + mActive = 0; if (t != 0) { t->requestExit(); } else { @@ -367,7 +368,9 @@ void AudioTrack::stop() t->mLock.lock(); } - if (android_atomic_and(~1, &mActive) == 1) { + AutoMutex lock(mLock); + if (mActive == 1) { + mActive = 0; mCblk->cv.signal(); mAudioTrack->stop(); // Cancel loops (If we are in the middle of a loop, playback @@ -407,7 +410,6 @@ void AudioTrack::flush() mMarkerReached = false; mUpdatePeriod = 0; - if (!mActive) { mAudioTrack->flush(); // Release AudioTrack callback thread in case it was waiting for new buffers @@ -419,7 +421,9 @@ void AudioTrack::flush() void AudioTrack::pause() { LOGV("pause"); - if (android_atomic_and(~1, &mActive) == 1) { + AutoMutex lock(mLock); + if (mActive == 1) { + mActive = 0; mAudioTrack->pause(); } } diff --git a/media/libmediaplayerservice/StagefrightRecorder.cpp b/media/libmediaplayerservice/StagefrightRecorder.cpp index dadd1db..ec3b5a2 100644 --- a/media/libmediaplayerservice/StagefrightRecorder.cpp +++ b/media/libmediaplayerservice/StagefrightRecorder.cpp @@ -864,7 +864,7 @@ status_t StagefrightRecorder::startAMRRecording() { return UNKNOWN_ERROR; } - mWriter = new AMRWriter(dup(mOutputFd)); + mWriter = new AMRWriter(mOutputFd); mWriter->addSource(audioEncoder); if (mMaxFileDurationUs != 0) { @@ -912,7 +912,7 @@ status_t StagefrightRecorder::startRTPRecording() { } } - mWriter = new ARTPWriter(dup(mOutputFd)); + mWriter = new ARTPWriter(mOutputFd); mWriter->addSource(source); mWriter->setListener(mListener); @@ -922,7 +922,7 @@ status_t StagefrightRecorder::startRTPRecording() { status_t StagefrightRecorder::startMPEG2TSRecording() { CHECK_EQ(mOutputFormat, OUTPUT_FORMAT_MPEG2TS); - sp<MediaWriter> writer = new MPEG2TSWriter(dup(mOutputFd)); + sp<MediaWriter> writer = new MPEG2TSWriter(mOutputFd); if (mAudioSource != AUDIO_SOURCE_LIST_END) { if (mAudioEncoder != AUDIO_ENCODER_AAC) { @@ -1204,7 +1204,7 @@ status_t StagefrightRecorder::setupMPEG4Recording( mediaWriter->clear(); *totalBitRate = 0; status_t err = OK; - sp<MediaWriter> writer = new MPEG4Writer(dup(outputFd)); + sp<MediaWriter> writer = new MPEG4Writer(outputFd); // Add audio source first if it exists if (!mCaptureTimeLapse && (mAudioSource != AUDIO_SOURCE_LIST_END)) { diff --git a/media/libstagefright/AMRExtractor.cpp b/media/libstagefright/AMRExtractor.cpp index 1b05528..ac87c29 100644 --- a/media/libstagefright/AMRExtractor.cpp +++ b/media/libstagefright/AMRExtractor.cpp @@ -55,7 +55,7 @@ private: size_t mFrameSize; bool mIsWide; - off_t mOffset; + off64_t mOffset; int64_t mCurrentTimeUs; bool mStarted; MediaBufferGroup *mGroup; @@ -115,9 +115,9 @@ AMRExtractor::AMRExtractor(const sp<DataSource> &source) mFrameSize = getFrameSize(mIsWide, FT); - off_t streamSize; + off64_t streamSize; if (mDataSource->getSize(&streamSize) == OK) { - off_t numFrames = streamSize / mFrameSize; + off64_t numFrames = streamSize / mFrameSize; mMeta->setInt64(kKeyDuration, 20000ll * numFrames); } diff --git a/media/libstagefright/AMRWriter.cpp b/media/libstagefright/AMRWriter.cpp index c0b1abe..0db3d1d 100644 --- a/media/libstagefright/AMRWriter.cpp +++ b/media/libstagefright/AMRWriter.cpp @@ -24,20 +24,28 @@ #include <media/mediarecorder.h> #include <sys/prctl.h> #include <sys/resource.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> namespace android { AMRWriter::AMRWriter(const char *filename) - : mFile(fopen(filename, "wb")), - mInitCheck(mFile != NULL ? OK : NO_INIT), + : mFd(-1), + mInitCheck(NO_INIT), mStarted(false), mPaused(false), mResumed(false) { + + mFd = open(filename, O_CREAT | O_LARGEFILE | O_TRUNC); + if (mFd >= 0) { + mInitCheck = OK; + } } AMRWriter::AMRWriter(int fd) - : mFile(fdopen(fd, "wb")), - mInitCheck(mFile != NULL ? OK : NO_INIT), + : mFd(dup(fd)), + mInitCheck(mFd < 0? NO_INIT: OK), mStarted(false), mPaused(false), mResumed(false) { @@ -48,9 +56,9 @@ AMRWriter::~AMRWriter() { stop(); } - if (mFile != NULL) { - fclose(mFile); - mFile = NULL; + if (mFd != -1) { + close(mFd); + mFd = -1; } } @@ -90,8 +98,8 @@ status_t AMRWriter::addSource(const sp<MediaSource> &source) { mSource = source; const char *kHeader = isWide ? "#!AMR-WB\n" : "#!AMR\n"; - size_t n = strlen(kHeader); - if (fwrite(kHeader, 1, n, mFile) != n) { + ssize_t n = strlen(kHeader); + if (write(mFd, kHeader, n) != n) { return ERROR_IO; } @@ -240,11 +248,9 @@ status_t AMRWriter::threadFunc() { notify(MEDIA_RECORDER_EVENT_INFO, MEDIA_RECORDER_INFO_MAX_DURATION_REACHED, 0); break; } - ssize_t n = fwrite( - (const uint8_t *)buffer->data() + buffer->range_offset(), - 1, - buffer->range_length(), - mFile); + ssize_t n = write(mFd, + (const uint8_t *)buffer->data() + buffer->range_offset(), + buffer->range_length()); if (n < (ssize_t)buffer->range_length()) { buffer->release(); @@ -266,9 +272,8 @@ status_t AMRWriter::threadFunc() { notify(MEDIA_RECORDER_EVENT_INFO, MEDIA_RECORDER_INFO_COMPLETION_STATUS, UNKNOWN_ERROR); } - fflush(mFile); - fclose(mFile); - mFile = NULL; + close(mFd); + mFd = -1; mReachedEOS = true; if (err == ERROR_END_OF_STREAM) { return OK; diff --git a/media/libstagefright/Android.mk b/media/libstagefright/Android.mk index 8fe1d4d..4ad1eb4 100644 --- a/media/libstagefright/Android.mk +++ b/media/libstagefright/Android.mk @@ -49,7 +49,6 @@ LOCAL_SRC_FILES:= \ WVMExtractor.cpp \ XINGSeeker.cpp \ avc_utils.cpp \ - string.cpp LOCAL_C_INCLUDES:= \ $(JNI_H_INCLUDE) \ diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp index 538e7bf..922aaa8 100644 --- a/media/libstagefright/AwesomePlayer.cpp +++ b/media/libstagefright/AwesomePlayer.cpp @@ -499,7 +499,7 @@ void AwesomePlayer::notifyListener_l(int msg, int ext1, int ext2) { } bool AwesomePlayer::getBitrate(int64_t *bitrate) { - off_t size; + off64_t size; if (mDurationUs >= 0 && mCachedSource != NULL && mCachedSource->getSize(&size) == OK) { *bitrate = size * 8000000ll / mDurationUs; // in bits/sec diff --git a/media/libstagefright/DataSource.cpp b/media/libstagefright/DataSource.cpp index 0b8997c..ee0d792 100644 --- a/media/libstagefright/DataSource.cpp +++ b/media/libstagefright/DataSource.cpp @@ -36,7 +36,7 @@ namespace android { -bool DataSource::getUInt16(off_t offset, uint16_t *x) { +bool DataSource::getUInt16(off64_t offset, uint16_t *x) { *x = 0; uint8_t byte[2]; @@ -49,7 +49,7 @@ bool DataSource::getUInt16(off_t offset, uint16_t *x) { return true; } -status_t DataSource::getSize(off_t *size) { +status_t DataSource::getSize(off64_t *size) { *size = 0; return ERROR_UNSUPPORTED; diff --git a/media/libstagefright/FileSource.cpp b/media/libstagefright/FileSource.cpp index 1c1a9c5..98d5b50 100644 --- a/media/libstagefright/FileSource.cpp +++ b/media/libstagefright/FileSource.cpp @@ -16,12 +16,16 @@ #include <media/stagefright/FileSource.h> #include <media/stagefright/MediaDebug.h> +#include <sys/types.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> namespace android { FileSource::FileSource(const char *filename) - : mFile(fopen(filename, "rb")), - mFd(mFile == NULL ? -1 : fileno(mFile)), + : mFd(-1), mOffset(0), mLength(-1), mDecryptHandle(NULL), @@ -29,11 +33,12 @@ FileSource::FileSource(const char *filename) mDrmBufOffset(0), mDrmBufSize(0), mDrmBuf(NULL){ + + mFd = open(filename, O_LARGEFILE | O_RDONLY); } FileSource::FileSource(int fd, int64_t offset, int64_t length) - : mFile(fdopen(fd, "rb")), - mFd(fd), + : mFd(fd), mOffset(offset), mLength(length), mDecryptHandle(NULL), @@ -46,9 +51,9 @@ FileSource::FileSource(int fd, int64_t offset, int64_t length) } FileSource::~FileSource() { - if (mFile != NULL) { - fclose(mFile); - mFile = NULL; + if (mFd >= 0) { + close(mFd); + mFd = -1; } if (mDrmBuf != NULL) { @@ -58,11 +63,11 @@ FileSource::~FileSource() { } status_t FileSource::initCheck() const { - return mFile != NULL ? OK : NO_INIT; + return mFd >= 0 ? OK : NO_INIT; } -ssize_t FileSource::readAt(off_t offset, void *data, size_t size) { - if (mFile == NULL) { +ssize_t FileSource::readAt(off64_t offset, void *data, size_t size) { + if (mFd < 0) { return NO_INIT; } @@ -82,18 +87,18 @@ ssize_t FileSource::readAt(off_t offset, void *data, size_t size) { == mDecryptHandle->decryptApiType) { return readAtDRM(offset, data, size); } else { - int err = fseeko(mFile, offset + mOffset, SEEK_SET); - if (err < 0) { + off64_t result = lseek64(mFd, offset + mOffset, SEEK_SET); + if (result == -1) { LOGE("seek to %lld failed", offset + mOffset); return UNKNOWN_ERROR; } - return fread(data, 1, size, mFile); + return ::read(mFd, data, size); } } -status_t FileSource::getSize(off_t *size) { - if (mFile == NULL) { +status_t FileSource::getSize(off64_t *size) { + if (mFd < 0) { return NO_INIT; } @@ -103,8 +108,7 @@ status_t FileSource::getSize(off_t *size) { return OK; } - fseek(mFile, 0, SEEK_END); - *size = ftello(mFile); + *size = lseek64(mFd, 0, SEEK_END); return OK; } @@ -133,7 +137,7 @@ void FileSource::getDrmInfo(DecryptHandle **handle, DrmManagerClient **client) { *client = mDrmManagerClient; } -ssize_t FileSource::readAtDRM(off_t offset, void *data, size_t size) { +ssize_t FileSource::readAtDRM(off64_t offset, void *data, size_t size) { size_t DRM_CACHE_SIZE = 1024; if (mDrmBuf == NULL) { mDrmBuf = new unsigned char[DRM_CACHE_SIZE]; diff --git a/media/libstagefright/HTTPStream.cpp b/media/libstagefright/HTTPStream.cpp index ccc6a34..e7f00aa 100644 --- a/media/libstagefright/HTTPStream.cpp +++ b/media/libstagefright/HTTPStream.cpp @@ -36,7 +36,7 @@ namespace android { // static -const char *HTTPStream::kStatusKey = ":status:"; +const char *HTTPStream::kStatusKey = ":status:"; // MUST be lowercase. HTTPStream::HTTPStream() : mState(READY), @@ -220,7 +220,7 @@ status_t HTTPStream::receive_header(int *http_status) { return err; } - mHeaders.add(string(kStatusKey), string(line)); + mHeaders.add(AString(kStatusKey), AString(line)); char *spacePos = strchr(line, ' '); if (spacePos == NULL) { @@ -264,7 +264,10 @@ status_t HTTPStream::receive_header(int *http_status) { char *colonPos = strchr(line, ':'); if (colonPos == NULL) { - mHeaders.add(string(line), string()); + AString key = line; + key.tolower(); + + mHeaders.add(key, AString()); } else { char *end_of_key = colonPos; while (end_of_key > line && isspace(end_of_key[-1])) { @@ -278,7 +281,10 @@ status_t HTTPStream::receive_header(int *http_status) { *end_of_key = '\0'; - mHeaders.add(string(line), string(start_of_value)); + AString key = line; + key.tolower(); + + mHeaders.add(key, AString(start_of_value)); } } @@ -314,8 +320,11 @@ ssize_t HTTPStream::receive(void *data, size_t size) { return (ssize_t)total; } -bool HTTPStream::find_header_value(const string &key, string *value) const { - ssize_t index = mHeaders.indexOfKey(key); +bool HTTPStream::find_header_value(const AString &key, AString *value) const { + AString key_lower = key; + key_lower.tolower(); + + ssize_t index = mHeaders.indexOfKey(key_lower); if (index < 0) { value->clear(); return false; diff --git a/media/libstagefright/JPEGSource.cpp b/media/libstagefright/JPEGSource.cpp index ec81097..e818115 100644 --- a/media/libstagefright/JPEGSource.cpp +++ b/media/libstagefright/JPEGSource.cpp @@ -142,7 +142,7 @@ status_t JPEGSource::parseJPEG() { mWidth = 0; mHeight = 0; - off_t i = 0; + off64_t i = 0; uint16_t soi; if (!mSource->getUInt16(i, &soi)) { diff --git a/media/libstagefright/MP3Extractor.cpp b/media/libstagefright/MP3Extractor.cpp index 84ced8f..9610f90 100644 --- a/media/libstagefright/MP3Extractor.cpp +++ b/media/libstagefright/MP3Extractor.cpp @@ -183,7 +183,7 @@ bool MP3Extractor::get_mp3_frame_size( static bool Resync( const sp<DataSource> &source, uint32_t match_header, - off_t *inout_pos, off_t *post_id3_pos, uint32_t *out_header) { + off64_t *inout_pos, off64_t *post_id3_pos, uint32_t *out_header) { if (post_id3_pos != NULL) { *post_id3_pos = 0; } @@ -226,7 +226,7 @@ static bool Resync( } } - off_t pos = *inout_pos; + off64_t pos = *inout_pos; bool valid = false; do { if (pos >= *inout_pos + 128 * 1024) { @@ -261,7 +261,7 @@ static bool Resync( // We found what looks like a valid frame, // now find its successors. - off_t test_pos = pos + frame_size; + off64_t test_pos = pos + frame_size; valid = true; for (int j = 0; j < 3; ++j) { @@ -312,7 +312,7 @@ class MP3Source : public MediaSource { public: MP3Source( const sp<MetaData> &meta, const sp<DataSource> &source, - off_t first_frame_pos, uint32_t fixed_header, + off64_t first_frame_pos, uint32_t fixed_header, const sp<MP3Seeker> &seeker); virtual status_t start(MetaData *params = NULL); @@ -329,9 +329,9 @@ protected: private: sp<MetaData> mMeta; sp<DataSource> mDataSource; - off_t mFirstFramePos; + off64_t mFirstFramePos; uint32_t mFixedHeader; - off_t mCurrentPos; + off64_t mCurrentPos; int64_t mCurrentTimeUs; bool mStarted; sp<MP3Seeker> mSeeker; @@ -347,8 +347,8 @@ MP3Extractor::MP3Extractor( mDataSource(source), mFirstFramePos(-1), mFixedHeader(0) { - off_t pos = 0; - off_t post_id3_pos; + off64_t pos = 0; + off64_t post_id3_pos; uint32_t header; bool success; @@ -361,9 +361,9 @@ MP3Extractor::MP3Extractor( && meta->findInt64("post-id3-offset", &meta_post_id3_offset)) { // The sniffer has already done all the hard work for us, simply // accept its judgement. - pos = (off_t)meta_offset; + pos = (off64_t)meta_offset; header = meta_header; - post_id3_pos = (off_t)meta_post_id3_offset; + post_id3_pos = (off64_t)meta_post_id3_offset; success = true; } else { @@ -401,7 +401,7 @@ MP3Extractor::MP3Extractor( int64_t durationUs; if (mSeeker == NULL || !mSeeker->getDuration(&durationUs)) { - off_t fileSize; + off64_t fileSize; if (mDataSource->getSize(&fileSize) == OK) { durationUs = 8000LL * (fileSize - mFirstFramePos) / bitrate; } else { @@ -442,7 +442,7 @@ sp<MetaData> MP3Extractor::getTrackMetaData(size_t index, uint32_t flags) { MP3Source::MP3Source( const sp<MetaData> &meta, const sp<DataSource> &source, - off_t first_frame_pos, uint32_t fixed_header, + off64_t first_frame_pos, uint32_t fixed_header, const sp<MP3Seeker> &seeker) : mMeta(meta), mDataSource(source), @@ -545,7 +545,7 @@ status_t MP3Source::read( // Lost sync. LOGV("lost sync! header = 0x%08x, old header = 0x%08x\n", header, mFixedHeader); - off_t pos = mCurrentPos; + off64_t pos = mCurrentPos; if (!Resync(mDataSource, mFixedHeader, &pos, NULL, NULL)) { LOGE("Unable to resync. Signalling end of stream."); @@ -651,8 +651,8 @@ sp<MetaData> MP3Extractor::getMetaData() { bool SniffMP3( const sp<DataSource> &source, String8 *mimeType, float *confidence, sp<AMessage> *meta) { - off_t pos = 0; - off_t post_id3_pos; + off64_t pos = 0; + off64_t post_id3_pos; uint32_t header; if (!Resync(source, 0, &pos, &post_id3_pos, &header)) { return false; diff --git a/media/libstagefright/MPEG2TSWriter.cpp b/media/libstagefright/MPEG2TSWriter.cpp index 81a2b0d..4d8165e 100644 --- a/media/libstagefright/MPEG2TSWriter.cpp +++ b/media/libstagefright/MPEG2TSWriter.cpp @@ -410,7 +410,7 @@ void MPEG2TSWriter::SourceInfo::onMessageReceived(const sp<AMessage> &msg) { //////////////////////////////////////////////////////////////////////////////// MPEG2TSWriter::MPEG2TSWriter(int fd) - : mFile(fdopen(fd, "wb")), + : mFile(fdopen(dup(fd), "wb")), mStarted(false), mNumSourcesDone(0), mNumTSPacketsWritten(0), diff --git a/media/libstagefright/MPEG4Extractor.cpp b/media/libstagefright/MPEG4Extractor.cpp index bb929fd..bbe99d3 100644 --- a/media/libstagefright/MPEG4Extractor.cpp +++ b/media/libstagefright/MPEG4Extractor.cpp @@ -98,11 +98,11 @@ struct MPEG4DataSource : public DataSource { MPEG4DataSource(const sp<DataSource> &source); virtual status_t initCheck() const; - virtual ssize_t readAt(off_t offset, void *data, size_t size); - virtual status_t getSize(off_t *size); + virtual ssize_t readAt(off64_t offset, void *data, size_t size); + virtual status_t getSize(off64_t *size); virtual uint32_t flags(); - status_t setCachedRange(off_t offset, size_t size); + status_t setCachedRange(off64_t offset, size_t size); protected: virtual ~MPEG4DataSource(); @@ -111,7 +111,7 @@ private: Mutex mLock; sp<DataSource> mSource; - off_t mCachedOffset; + off64_t mCachedOffset; size_t mCachedSize; uint8_t *mCache; @@ -146,7 +146,7 @@ status_t MPEG4DataSource::initCheck() const { return mSource->initCheck(); } -ssize_t MPEG4DataSource::readAt(off_t offset, void *data, size_t size) { +ssize_t MPEG4DataSource::readAt(off64_t offset, void *data, size_t size) { Mutex::Autolock autoLock(mLock); if (offset >= mCachedOffset @@ -158,7 +158,7 @@ ssize_t MPEG4DataSource::readAt(off_t offset, void *data, size_t size) { return mSource->readAt(offset, data, size); } -status_t MPEG4DataSource::getSize(off_t *size) { +status_t MPEG4DataSource::getSize(off64_t *size) { return mSource->getSize(size); } @@ -166,7 +166,7 @@ uint32_t MPEG4DataSource::flags() { return mSource->flags(); } -status_t MPEG4DataSource::setCachedRange(off_t offset, size_t size) { +status_t MPEG4DataSource::setCachedRange(off64_t offset, size_t size) { Mutex::Autolock autoLock(mLock); clearCache(); @@ -363,7 +363,7 @@ status_t MPEG4Extractor::readMetaData() { return OK; } - off_t offset = 0; + off64_t offset = 0; status_t err; while ((err = parseChunk(&offset, 0)) == OK) { } @@ -404,7 +404,7 @@ char* MPEG4Extractor::getDrmTrackInfo(size_t trackID, int *len) { } // Reads an encoded integer 7 bits at a time until it encounters the high bit clear. -int32_t readSize(off_t offset, +int32_t readSize(off64_t offset, const sp<DataSource> DataSource, uint8_t *numOfBytes) { uint32_t size = 0; uint8_t data; @@ -424,7 +424,7 @@ int32_t readSize(off_t offset, return size; } -status_t MPEG4Extractor::parseDrmSINF(off_t *offset, off_t data_offset) { +status_t MPEG4Extractor::parseDrmSINF(off64_t *offset, off64_t data_offset) { uint8_t updateIdTag; if (mDataSource->readAt(data_offset, &updateIdTag, 1) < 1) { return ERROR_IO; @@ -596,14 +596,14 @@ static void convertTimeToDate(int64_t time_1904, String8 *s) { s->setTo(tmp); } -status_t MPEG4Extractor::parseChunk(off_t *offset, int depth) { +status_t MPEG4Extractor::parseChunk(off64_t *offset, int depth) { uint32_t hdr[2]; if (mDataSource->readAt(*offset, hdr, 8) < 8) { return ERROR_IO; } uint64_t chunk_size = ntohl(hdr[0]); uint32_t chunk_type = ntohl(hdr[1]); - off_t data_offset = *offset + 8; + off64_t data_offset = *offset + 8; if (chunk_size == 1) { if (mDataSource->readAt(*offset + 8, &chunk_size, 8) < 8) { @@ -644,11 +644,11 @@ status_t MPEG4Extractor::parseChunk(off_t *offset, int depth) { PathAdder autoAdder(&mPath, chunk_type); - off_t chunk_data_size = *offset + chunk_size - data_offset; + off64_t chunk_data_size = *offset + chunk_size - data_offset; if (chunk_type != FOURCC('c', 'p', 'r', 't') && mPath.size() == 5 && underMetaDataPath(mPath)) { - off_t stop_offset = *offset + chunk_size; + off64_t stop_offset = *offset + chunk_size; *offset = data_offset; while (*offset < stop_offset) { status_t err = parseChunk(offset, depth + 1); @@ -715,7 +715,7 @@ status_t MPEG4Extractor::parseChunk(off_t *offset, int depth) { track->meta->setCString(kKeyMIMEType, "application/octet-stream"); } - off_t stop_offset = *offset + chunk_size; + off64_t stop_offset = *offset + chunk_size; *offset = data_offset; while (*offset < stop_offset) { status_t err = parseChunk(offset, depth + 1); @@ -788,7 +788,7 @@ status_t MPEG4Extractor::parseChunk(off_t *offset, int depth) { return ERROR_IO; } - off_t timescale_offset; + off64_t timescale_offset; if (version == 1) { timescale_offset = data_offset + 4 + 16; @@ -838,7 +838,7 @@ status_t MPEG4Extractor::parseChunk(off_t *offset, int depth) { } uint8_t buffer[8]; - if (chunk_data_size < (off_t)sizeof(buffer)) { + if (chunk_data_size < (off64_t)sizeof(buffer)) { return ERROR_MALFORMED; } @@ -862,7 +862,7 @@ status_t MPEG4Extractor::parseChunk(off_t *offset, int depth) { break; } - off_t stop_offset = *offset + chunk_size; + off64_t stop_offset = *offset + chunk_size; *offset = data_offset + 8; for (uint32_t i = 0; i < entry_count; ++i) { status_t err = parseChunk(offset, depth + 1); @@ -919,7 +919,7 @@ status_t MPEG4Extractor::parseChunk(off_t *offset, int depth) { mLastTrack->meta->setInt32(kKeyChannelCount, num_channels); mLastTrack->meta->setInt32(kKeySampleRate, sample_rate); - off_t stop_offset = *offset + chunk_size; + off64_t stop_offset = *offset + chunk_size; *offset = data_offset + sizeof(buffer); while (*offset < stop_offset) { status_t err = parseChunk(offset, depth + 1); @@ -962,7 +962,7 @@ status_t MPEG4Extractor::parseChunk(off_t *offset, int depth) { mLastTrack->meta->setInt32(kKeyWidth, width); mLastTrack->meta->setInt32(kKeyHeight, height); - off_t stop_offset = *offset + chunk_size; + off64_t stop_offset = *offset + chunk_size; *offset = data_offset + sizeof(buffer); while (*offset < stop_offset) { status_t err = parseChunk(offset, depth + 1); @@ -1069,7 +1069,7 @@ status_t MPEG4Extractor::parseChunk(off_t *offset, int depth) { } uint8_t buffer[256]; - if (chunk_data_size > (off_t)sizeof(buffer)) { + if (chunk_data_size > (off64_t)sizeof(buffer)) { return ERROR_BUFFER_TOO_SMALL; } @@ -1108,7 +1108,7 @@ status_t MPEG4Extractor::parseChunk(off_t *offset, int depth) { case FOURCC('a', 'v', 'c', 'C'): { char buffer[256]; - if (chunk_data_size > (off_t)sizeof(buffer)) { + if (chunk_data_size > (off64_t)sizeof(buffer)) { return ERROR_BUFFER_TOO_SMALL; } @@ -1127,7 +1127,7 @@ status_t MPEG4Extractor::parseChunk(off_t *offset, int depth) { case FOURCC('m', 'e', 't', 'a'): { uint8_t buffer[4]; - if (chunk_data_size < (off_t)sizeof(buffer)) { + if (chunk_data_size < (off64_t)sizeof(buffer)) { return ERROR_MALFORMED; } @@ -1147,7 +1147,7 @@ status_t MPEG4Extractor::parseChunk(off_t *offset, int depth) { return OK; } - off_t stop_offset = *offset + chunk_size; + off64_t stop_offset = *offset + chunk_size; *offset = data_offset + sizeof(buffer); while (*offset < stop_offset) { status_t err = parseChunk(offset, depth + 1); @@ -1232,7 +1232,7 @@ status_t MPEG4Extractor::parseChunk(off_t *offset, int depth) { } status_t MPEG4Extractor::parseTrackHeader( - off_t data_offset, off_t data_size) { + off64_t data_offset, off64_t data_size) { if (data_size < 4) { return ERROR_MALFORMED; } @@ -1246,7 +1246,7 @@ status_t MPEG4Extractor::parseTrackHeader( uint8_t buffer[36 + 60]; - if (data_size != (off_t)dynSize + 60) { + if (data_size != (off64_t)dynSize + 60) { return ERROR_MALFORMED; } @@ -1318,7 +1318,7 @@ status_t MPEG4Extractor::parseTrackHeader( return OK; } -status_t MPEG4Extractor::parseMetaData(off_t offset, size_t size) { +status_t MPEG4Extractor::parseMetaData(off64_t offset, size_t size) { if (size < 4) { return ERROR_MALFORMED; } @@ -1807,7 +1807,7 @@ status_t MPEG4Source::read( // fall through } - off_t offset; + off64_t offset; size_t size; uint32_t dts; bool isSyncSample; diff --git a/media/libstagefright/MPEG4Writer.cpp b/media/libstagefright/MPEG4Writer.cpp index 17a40b0..6760707 100644 --- a/media/libstagefright/MPEG4Writer.cpp +++ b/media/libstagefright/MPEG4Writer.cpp @@ -33,6 +33,10 @@ #include <media/stagefright/MediaSource.h> #include <media/stagefright/Utils.h> #include <media/mediarecorder.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> #include "include/ESDS.h" @@ -64,7 +68,7 @@ public: bool isAvc() const { return mIsAvc; } bool isAudio() const { return mIsAudio; } bool isMPEG4() const { return mIsMPEG4; } - void addChunkOffset(off_t offset); + void addChunkOffset(off64_t offset); status_t dump(int fd, const Vector<String16>& args) const; private: @@ -99,7 +103,7 @@ private: List<MediaBuffer *> mChunkSamples; size_t mNumStcoTableEntries; - List<off_t> mChunkOffsets; + List<off64_t> mChunkOffsets; size_t mNumStscTableEntries; struct StscTableEntry { @@ -214,7 +218,8 @@ private: }; MPEG4Writer::MPEG4Writer(const char *filename) - : mFile(fopen(filename, "wb")), + : mFd(-1), + mInitCheck(NO_INIT), mUse4ByteNalLength(true), mUse32BitOffset(true), mIsFileSizeLimitExplicitlyRequested(false), @@ -224,11 +229,16 @@ MPEG4Writer::MPEG4Writer(const char *filename) mMdatOffset(0), mEstimatedMoovBoxSize(0), mInterleaveDurationUs(1000000) { - CHECK(mFile != NULL); + + mFd = open(filename, O_CREAT | O_LARGEFILE | O_TRUNC); + if (mFd >= 0) { + mInitCheck = OK; + } } MPEG4Writer::MPEG4Writer(int fd) - : mFile(fdopen(fd, "wb")), + : mFd(dup(fd)), + mInitCheck(mFd < 0? NO_INIT: OK), mUse4ByteNalLength(true), mUse32BitOffset(true), mIsFileSizeLimitExplicitlyRequested(false), @@ -238,7 +248,6 @@ MPEG4Writer::MPEG4Writer(int fd) mMdatOffset(0), mEstimatedMoovBoxSize(0), mInterleaveDurationUs(1000000) { - CHECK(mFile != NULL); } MPEG4Writer::~MPEG4Writer() { @@ -368,7 +377,7 @@ int64_t MPEG4Writer::estimateMoovBoxSize(int32_t bitRate) { } status_t MPEG4Writer::start(MetaData *param) { - if (mFile == NULL) { + if (mInitCheck != OK) { return UNKNOWN_ERROR; } @@ -459,13 +468,13 @@ status_t MPEG4Writer::start(MetaData *param) { mEstimatedMoovBoxSize = estimateMoovBoxSize(bitRate); } CHECK(mEstimatedMoovBoxSize >= 8); - fseeko(mFile, mFreeBoxOffset, SEEK_SET); + lseek64(mFd, mFreeBoxOffset, SEEK_SET); writeInt32(mEstimatedMoovBoxSize); write("free", 4); mMdatOffset = mFreeBoxOffset + mEstimatedMoovBoxSize; mOffset = mMdatOffset; - fseeko(mFile, mMdatOffset, SEEK_SET); + lseek64(mFd, mMdatOffset, SEEK_SET); if (mUse32BitOffset) { write("????mdat", 8); } else { @@ -491,7 +500,7 @@ bool MPEG4Writer::use32BitFileOffset() const { } status_t MPEG4Writer::pause() { - if (mFile == NULL) { + if (mInitCheck != OK) { return OK; } mPaused = true; @@ -575,7 +584,7 @@ void MPEG4Writer::writeCompositionMatrix(int degrees) { status_t MPEG4Writer::stop() { - if (mFile == NULL) { + if (mInitCheck != OK) { return OK; } @@ -598,28 +607,28 @@ status_t MPEG4Writer::stop() { // Do not write out movie header on error. if (err != OK) { - fflush(mFile); - fclose(mFile); - mFile = NULL; + close(mFd); + mFd = -1; + mInitCheck = NO_INIT; mStarted = false; return err; } // Fix up the size of the 'mdat' chunk. if (mUse32BitOffset) { - fseeko(mFile, mMdatOffset, SEEK_SET); + lseek64(mFd, mMdatOffset, SEEK_SET); int32_t size = htonl(static_cast<int32_t>(mOffset - mMdatOffset)); - fwrite(&size, 1, 4, mFile); + ::write(mFd, &size, 4); } else { - fseeko(mFile, mMdatOffset + 8, SEEK_SET); + lseek64(mFd, mMdatOffset + 8, SEEK_SET); int64_t size = mOffset - mMdatOffset; size = hton64(size); - fwrite(&size, 1, 8, mFile); + ::write(mFd, &size, 8); } - fseeko(mFile, mOffset, SEEK_SET); + lseek64(mFd, mOffset, SEEK_SET); time_t now = time(NULL); - const off_t moovOffset = mOffset; + const off64_t moovOffset = mOffset; mWriteMoovBoxToMemory = true; mMoovBoxBuffer = (uint8_t *) malloc(mEstimatedMoovBoxSize); mMoovBoxBufferOffset = 0; @@ -661,12 +670,12 @@ status_t MPEG4Writer::stop() { CHECK(mMoovBoxBufferOffset + 8 <= mEstimatedMoovBoxSize); // Moov box - fseeko(mFile, mFreeBoxOffset, SEEK_SET); + lseek64(mFd, mFreeBoxOffset, SEEK_SET); mOffset = mFreeBoxOffset; - write(mMoovBoxBuffer, 1, mMoovBoxBufferOffset, mFile); + write(mMoovBoxBuffer, 1, mMoovBoxBufferOffset); // Free box - fseeko(mFile, mOffset, SEEK_SET); + lseek64(mFd, mOffset, SEEK_SET); writeInt32(mEstimatedMoovBoxSize - mMoovBoxBufferOffset); write("free", 4); @@ -680,9 +689,9 @@ status_t MPEG4Writer::stop() { CHECK(mBoxes.empty()); - fflush(mFile); - fclose(mFile); - mFile = NULL; + close(mFd); + mFd = -1; + mInitCheck = NO_INIT; mStarted = false; return err; } @@ -700,11 +709,12 @@ void MPEG4Writer::unlock() { mLock.unlock(); } -off_t MPEG4Writer::addSample_l(MediaBuffer *buffer) { - off_t old_offset = mOffset; +off64_t MPEG4Writer::addSample_l(MediaBuffer *buffer) { + off64_t old_offset = mOffset; - fwrite((const uint8_t *)buffer->data() + buffer->range_offset(), - 1, buffer->range_length(), mFile); + ::write(mFd, + (const uint8_t *)buffer->data() + buffer->range_offset(), + buffer->range_length()); mOffset += buffer->range_length(); @@ -725,33 +735,34 @@ static void StripStartcode(MediaBuffer *buffer) { } } -off_t MPEG4Writer::addLengthPrefixedSample_l(MediaBuffer *buffer) { - off_t old_offset = mOffset; +off64_t MPEG4Writer::addLengthPrefixedSample_l(MediaBuffer *buffer) { + off64_t old_offset = mOffset; size_t length = buffer->range_length(); if (mUse4ByteNalLength) { uint8_t x = length >> 24; - fwrite(&x, 1, 1, mFile); + ::write(mFd, &x, 1); x = (length >> 16) & 0xff; - fwrite(&x, 1, 1, mFile); + ::write(mFd, &x, 1); x = (length >> 8) & 0xff; - fwrite(&x, 1, 1, mFile); + ::write(mFd, &x, 1); x = length & 0xff; - fwrite(&x, 1, 1, mFile); + ::write(mFd, &x, 1); + + ::write(mFd, + (const uint8_t *)buffer->data() + buffer->range_offset(), + length); - fwrite((const uint8_t *)buffer->data() + buffer->range_offset(), - 1, length, mFile); mOffset += length + 4; } else { CHECK(length < 65536); uint8_t x = length >> 8; - fwrite(&x, 1, 1, mFile); + ::write(mFd, &x, 1); x = length & 0xff; - fwrite(&x, 1, 1, mFile); - fwrite((const uint8_t *)buffer->data() + buffer->range_offset(), - 1, length, mFile); + ::write(mFd, &x, 1); + ::write(mFd, (const uint8_t *)buffer->data() + buffer->range_offset(), length); mOffset += length + 2; } @@ -759,19 +770,21 @@ off_t MPEG4Writer::addLengthPrefixedSample_l(MediaBuffer *buffer) { } size_t MPEG4Writer::write( - const void *ptr, size_t size, size_t nmemb, FILE *stream) { + const void *ptr, size_t size, size_t nmemb) { const size_t bytes = size * nmemb; if (mWriteMoovBoxToMemory) { - off_t moovBoxSize = 8 + mMoovBoxBufferOffset + bytes; + // This happens only when we write the moov box at the end of + // recording, not for each output video/audio frame we receive. + off64_t moovBoxSize = 8 + mMoovBoxBufferOffset + bytes; if (moovBoxSize > mEstimatedMoovBoxSize) { - for (List<off_t>::iterator it = mBoxes.begin(); + for (List<off64_t>::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it) { (*it) += mOffset; } - fseeko(mFile, mOffset, SEEK_SET); - fwrite(mMoovBoxBuffer, 1, mMoovBoxBufferOffset, stream); - fwrite(ptr, size, nmemb, stream); + lseek64(mFd, mOffset, SEEK_SET); + ::write(mFd, mMoovBoxBuffer, mMoovBoxBufferOffset); + ::write(mFd, ptr, size * nmemb); mOffset += (bytes + mMoovBoxBufferOffset); free(mMoovBoxBuffer); mMoovBoxBuffer = NULL; @@ -783,7 +796,7 @@ size_t MPEG4Writer::write( mMoovBoxBufferOffset += bytes; } } else { - fwrite(ptr, size, nmemb, stream); + ::write(mFd, ptr, size * nmemb); mOffset += bytes; } return bytes; @@ -802,51 +815,51 @@ void MPEG4Writer::beginBox(const char *fourcc) { void MPEG4Writer::endBox() { CHECK(!mBoxes.empty()); - off_t offset = *--mBoxes.end(); + off64_t offset = *--mBoxes.end(); mBoxes.erase(--mBoxes.end()); if (mWriteMoovBoxToMemory) { int32_t x = htonl(mMoovBoxBufferOffset - offset); memcpy(mMoovBoxBuffer + offset, &x, 4); } else { - fseeko(mFile, offset, SEEK_SET); + lseek64(mFd, offset, SEEK_SET); writeInt32(mOffset - offset); mOffset -= 4; - fseeko(mFile, mOffset, SEEK_SET); + lseek64(mFd, mOffset, SEEK_SET); } } void MPEG4Writer::writeInt8(int8_t x) { - write(&x, 1, 1, mFile); + write(&x, 1, 1); } void MPEG4Writer::writeInt16(int16_t x) { x = htons(x); - write(&x, 1, 2, mFile); + write(&x, 1, 2); } void MPEG4Writer::writeInt32(int32_t x) { x = htonl(x); - write(&x, 1, 4, mFile); + write(&x, 1, 4); } void MPEG4Writer::writeInt64(int64_t x) { x = hton64(x); - write(&x, 1, 8, mFile); + write(&x, 1, 8); } void MPEG4Writer::writeCString(const char *s) { size_t n = strlen(s); - write(s, 1, n + 1, mFile); + write(s, 1, n + 1); } void MPEG4Writer::writeFourcc(const char *s) { CHECK_EQ(strlen(s), 4); - write(s, 1, 4, mFile); + write(s, 1, 4); } void MPEG4Writer::write(const void *data, size_t size) { - write(data, 1, size, mFile); + write(data, 1, size); } bool MPEG4Writer::isFileStreamable() const { @@ -987,7 +1000,7 @@ void MPEG4Writer::Track::addOneSttsTableEntry( ++mNumSttsTableEntries; } -void MPEG4Writer::Track::addChunkOffset(off_t offset) { +void MPEG4Writer::Track::addChunkOffset(off64_t offset) { ++mNumStcoTableEntries; mChunkOffsets.push_back(offset); } @@ -1102,7 +1115,7 @@ void MPEG4Writer::writeFirstChunk(ChunkInfo* info) { for (List<MediaBuffer *>::iterator it = chunkIt->mSamples.begin(); it != chunkIt->mSamples.end(); ++it) { - off_t offset = info->mTrack->isAvc() + off64_t offset = info->mTrack->isAvc() ? addLengthPrefixedSample_l(*it) : addSample_l(*it); if (it == chunkIt->mSamples.begin()) { @@ -1926,7 +1939,7 @@ status_t MPEG4Writer::Track::threadEntry() { trackProgressStatus(timestampUs); } if (mOwner->numTracks() == 1) { - off_t offset = mIsAvc? mOwner->addLengthPrefixedSample_l(copy) + off64_t offset = mIsAvc? mOwner->addLengthPrefixedSample_l(copy) : mOwner->addSample_l(copy); if (mChunkOffsets.empty()) { addChunkOffset(offset); @@ -2477,7 +2490,7 @@ void MPEG4Writer::Track::writeTrackHeader( mOwner->beginBox(use32BitOffset? "stco": "co64"); mOwner->writeInt32(0); // version=0, flags=0 mOwner->writeInt32(mNumStcoTableEntries); - for (List<off_t>::iterator it = mChunkOffsets.begin(); + for (List<off64_t>::iterator it = mChunkOffsets.begin(); it != mChunkOffsets.end(); ++it) { if (use32BitOffset) { mOwner->writeInt32(static_cast<int32_t>(*it)); diff --git a/media/libstagefright/NuCachedSource2.cpp b/media/libstagefright/NuCachedSource2.cpp index 3bb38de..829ab20 100644 --- a/media/libstagefright/NuCachedSource2.cpp +++ b/media/libstagefright/NuCachedSource2.cpp @@ -201,7 +201,7 @@ status_t NuCachedSource2::initCheck() const { return mSource->initCheck(); } -status_t NuCachedSource2::getSize(off_t *size) { +status_t NuCachedSource2::getSize(off64_t *size) { return mSource->getSize(size); } @@ -353,7 +353,7 @@ void NuCachedSource2::restartPrefetcherIfNecessary_l( mFetching = true; } -ssize_t NuCachedSource2::readAt(off_t offset, void *data, size_t size) { +ssize_t NuCachedSource2::readAt(off64_t offset, void *data, size_t size) { Mutex::Autolock autoSerializer(mSerializer); LOGV("readAt offset %ld, size %d", offset, size); @@ -408,27 +408,27 @@ size_t NuCachedSource2::approxDataRemaining(bool *eos) { size_t NuCachedSource2::approxDataRemaining_l(bool *eos) { *eos = (mFinalStatus != OK); - off_t lastBytePosCached = mCacheOffset + mCache->totalSize(); + off64_t lastBytePosCached = mCacheOffset + mCache->totalSize(); if (mLastAccessPos < lastBytePosCached) { return lastBytePosCached - mLastAccessPos; } return 0; } -ssize_t NuCachedSource2::readInternal(off_t offset, void *data, size_t size) { +ssize_t NuCachedSource2::readInternal(off64_t offset, void *data, size_t size) { LOGV("readInternal offset %ld size %d", offset, size); Mutex::Autolock autoLock(mLock); if (offset < mCacheOffset - || offset >= (off_t)(mCacheOffset + mCache->totalSize())) { - static const off_t kPadding = 32768; + || offset >= (off64_t)(mCacheOffset + mCache->totalSize())) { + static const off64_t kPadding = 32768; // In the presence of multiple decoded streams, once of them will // trigger this seek request, the other one will request data "nearby" // soon, adjust the seek position so that that subsequent request // does not trigger another seek. - off_t seekOffset = (offset > kPadding) ? offset - kPadding : 0; + off64_t seekOffset = (offset > kPadding) ? offset - kPadding : 0; seekInternal_l(seekOffset); } @@ -457,15 +457,15 @@ ssize_t NuCachedSource2::readInternal(off_t offset, void *data, size_t size) { return -EAGAIN; } -status_t NuCachedSource2::seekInternal_l(off_t offset) { +status_t NuCachedSource2::seekInternal_l(off64_t offset) { mLastAccessPos = offset; if (offset >= mCacheOffset - && offset <= (off_t)(mCacheOffset + mCache->totalSize())) { + && offset <= (off64_t)(mCacheOffset + mCache->totalSize())) { return OK; } - LOGI("new range: offset= %ld", offset); + LOGI("new range: offset= %lld", offset); mCacheOffset = offset; diff --git a/media/libstagefright/NuHTTPDataSource.cpp b/media/libstagefright/NuHTTPDataSource.cpp index c3c0d81..269b233 100644 --- a/media/libstagefright/NuHTTPDataSource.cpp +++ b/media/libstagefright/NuHTTPDataSource.cpp @@ -84,7 +84,7 @@ NuHTTPDataSource::~NuHTTPDataSource() { status_t NuHTTPDataSource::connect( const char *uri, const KeyedVector<String8, String8> *overrides, - off_t offset) { + off64_t offset) { String8 headers; MakeFullHeaders(overrides, &headers); @@ -94,7 +94,7 @@ status_t NuHTTPDataSource::connect( status_t NuHTTPDataSource::connect( const char *uri, const String8 &headers, - off_t offset) { + off64_t offset) { String8 host, path; unsigned port; @@ -115,8 +115,8 @@ static bool IsRedirectStatusCode(int httpStatus) { status_t NuHTTPDataSource::connect( const char *host, unsigned port, const char *path, const String8 &headers, - off_t offset) { - LOGI("connect to %s:%u%s @%ld", host, port, path, offset); + off64_t offset) { + LOGI("connect to %s:%u%s @%lld", host, port, path, offset); bool needsToReconnect = true; @@ -162,7 +162,7 @@ status_t NuHTTPDataSource::connect( if (offset != 0) { char rangeHeader[128]; - sprintf(rangeHeader, "Range: bytes=%ld-\r\n", offset); + sprintf(rangeHeader, "Range: bytes=%lld-\r\n", offset); request.append(rangeHeader); } @@ -178,7 +178,7 @@ status_t NuHTTPDataSource::connect( } if (IsRedirectStatusCode(httpStatus)) { - string value; + AString value; CHECK(mHTTP.find_header_value("Location", &value)); mState = DISCONNECTED; @@ -198,9 +198,8 @@ status_t NuHTTPDataSource::connect( mHasChunkedTransferEncoding = false; { - string value; - if (mHTTP.find_header_value("Transfer-Encoding", &value) - || mHTTP.find_header_value("Transfer-encoding", &value)) { + AString value; + if (mHTTP.find_header_value("Transfer-Encoding", &value)) { // We don't currently support any transfer encodings but // chunked. @@ -222,11 +221,11 @@ status_t NuHTTPDataSource::connect( applyTimeoutResponse(); if (offset == 0) { - string value; + AString value; unsigned long x; - if (mHTTP.find_header_value(string("Content-Length"), &value) + if (mHTTP.find_header_value(AString("Content-Length"), &value) && ParseSingleUnsignedLong(value.c_str(), &x)) { - mContentLength = (off_t)x; + mContentLength = (off64_t)x; mContentLengthValid = true; } else { LOGW("Server did not give us the content length!"); @@ -239,9 +238,9 @@ status_t NuHTTPDataSource::connect( return ERROR_UNSUPPORTED; } - string value; + AString value; unsigned long x; - if (mHTTP.find_header_value(string("Content-Range"), &value)) { + if (mHTTP.find_header_value(AString("Content-Range"), &value)) { const char *slashPos = strchr(value.c_str(), '/'); if (slashPos != NULL && ParseSingleUnsignedLong(slashPos + 1, &x)) { @@ -331,7 +330,7 @@ ssize_t NuHTTPDataSource::internalRead(void *data, size_t size) { return n; } -ssize_t NuHTTPDataSource::readAt(off_t offset, void *data, size_t size) { +ssize_t NuHTTPDataSource::readAt(off64_t offset, void *data, size_t size) { LOGV("readAt offset %ld, size %d", offset, size); Mutex::Autolock autoLock(mLock); @@ -388,7 +387,7 @@ ssize_t NuHTTPDataSource::readAt(off_t offset, void *data, size_t size) { return numBytesRead; } -status_t NuHTTPDataSource::getSize(off_t *size) { +status_t NuHTTPDataSource::getSize(off64_t *size) { *size = 0; if (mState != CONNECTED) { @@ -439,7 +438,7 @@ void NuHTTPDataSource::MakeFullHeaders( } void NuHTTPDataSource::applyTimeoutResponse() { - string timeout; + AString timeout; if (mHTTP.find_header_value("X-SocketTimeout", &timeout)) { const char *s = timeout.c_str(); char *end; diff --git a/media/libstagefright/OggExtractor.cpp b/media/libstagefright/OggExtractor.cpp index 43938b2..4b8a014 100644 --- a/media/libstagefright/OggExtractor.cpp +++ b/media/libstagefright/OggExtractor.cpp @@ -73,7 +73,7 @@ struct MyVorbisExtractor { // Returns an approximate bitrate in bits per second. uint64_t approxBitrate(); - status_t seekToOffset(off_t offset); + status_t seekToOffset(off64_t offset); status_t readNextPacket(MediaBuffer **buffer); status_t init(); @@ -91,7 +91,7 @@ private: }; sp<DataSource> mSource; - off_t mOffset; + off64_t mOffset; Page mCurrentPage; uint64_t mPrevGranulePosition; size_t mCurrentPageSize; @@ -99,7 +99,7 @@ private: uint64_t mCurrentPageSamples; size_t mNextLaceIndex; - off_t mFirstDataOffset; + off64_t mFirstDataOffset; vorbis_info mVi; vorbis_comment mVc; @@ -107,8 +107,8 @@ private: sp<MetaData> mMeta; sp<MetaData> mFileMeta; - ssize_t readPage(off_t offset, Page *page); - status_t findNextPage(off_t startOffset, off_t *pageOffset); + ssize_t readPage(off64_t offset, Page *page); + status_t findNextPage(off64_t startOffset, off64_t *pageOffset); status_t verifyHeader( MediaBuffer *buffer, uint8_t type); @@ -116,7 +116,7 @@ private: void parseFileMetaData(); void extractAlbumArt(const void *data, size_t size); - uint64_t findPrevGranulePosition(off_t pageOffset); + uint64_t findPrevGranulePosition(off64_t pageOffset); MyVorbisExtractor(const MyVorbisExtractor &); MyVorbisExtractor &operator=(const MyVorbisExtractor &); @@ -162,7 +162,7 @@ status_t OggSource::read( int64_t seekTimeUs; ReadOptions::SeekMode mode; if (options && options->getSeekTo(&seekTimeUs, &mode)) { - off_t pos = seekTimeUs * mExtractor->mImpl->approxBitrate() / 8000000ll; + off64_t pos = seekTimeUs * mExtractor->mImpl->approxBitrate() / 8000000ll; LOGV("seeking to offset %ld", pos); if (mExtractor->mImpl->seekToOffset(pos) != OK) { @@ -220,7 +220,7 @@ sp<MetaData> MyVorbisExtractor::getFormat() const { } status_t MyVorbisExtractor::findNextPage( - off_t startOffset, off_t *pageOffset) { + off64_t startOffset, off64_t *pageOffset) { *pageOffset = startOffset; for (;;) { @@ -250,9 +250,9 @@ status_t MyVorbisExtractor::findNextPage( // it (if any) and return its granule position. // To do this we back up from the "current" page's offset until we find any // page preceding it and then scan forward to just before the current page. -uint64_t MyVorbisExtractor::findPrevGranulePosition(off_t pageOffset) { - off_t prevPageOffset = 0; - off_t prevGuess = pageOffset; +uint64_t MyVorbisExtractor::findPrevGranulePosition(off64_t pageOffset) { + off64_t prevPageOffset = 0; + off64_t prevGuess = pageOffset; for (;;) { if (prevGuess >= 5000) { prevGuess -= 5000; @@ -292,14 +292,14 @@ uint64_t MyVorbisExtractor::findPrevGranulePosition(off_t pageOffset) { } } -status_t MyVorbisExtractor::seekToOffset(off_t offset) { +status_t MyVorbisExtractor::seekToOffset(off64_t offset) { if (mFirstDataOffset >= 0 && offset < mFirstDataOffset) { // Once we know where the actual audio data starts (past the headers) // don't ever seek to anywhere before that. offset = mFirstDataOffset; } - off_t pageOffset; + off64_t pageOffset; status_t err = findNextPage(offset, &pageOffset); if (err != OK) { @@ -324,7 +324,7 @@ status_t MyVorbisExtractor::seekToOffset(off_t offset) { return OK; } -ssize_t MyVorbisExtractor::readPage(off_t offset, Page *page) { +ssize_t MyVorbisExtractor::readPage(off64_t offset, Page *page) { uint8_t header[27]; if (mSource->readAt(offset, header, sizeof(header)) < (ssize_t)sizeof(header)) { @@ -410,7 +410,7 @@ status_t MyVorbisExtractor::readNextPacket(MediaBuffer **out) { } if (mNextLaceIndex < mCurrentPage.mNumSegments) { - off_t dataOffset = mOffset + 27 + mCurrentPage.mNumSegments; + off64_t dataOffset = mOffset + 27 + mCurrentPage.mNumSegments; for (size_t j = 0; j < mNextLaceIndex; ++j) { dataOffset += mCurrentPage.mLace[j]; } @@ -609,7 +609,7 @@ status_t MyVorbisExtractor::verifyHeader( LOGV("nominal-bitrate = %ld", mVi.bitrate_nominal); LOGV("window-bitrate = %ld", mVi.bitrate_window); - off_t size; + off64_t size; if (mSource->getSize(&size) == OK) { uint64_t bps = approxBitrate(); diff --git a/media/libstagefright/SampleIterator.cpp b/media/libstagefright/SampleIterator.cpp index 7155c61..062ab9b 100644 --- a/media/libstagefright/SampleIterator.cpp +++ b/media/libstagefright/SampleIterator.cpp @@ -179,7 +179,7 @@ status_t SampleIterator::findChunkRange(uint32_t sampleIndex) { return OK; } -status_t SampleIterator::getChunkOffset(uint32_t chunk, off_t *offset) { +status_t SampleIterator::getChunkOffset(uint32_t chunk, off64_t *offset) { *offset = 0; if (chunk >= mTable->mNumChunkOffsets) { diff --git a/media/libstagefright/SampleTable.cpp b/media/libstagefright/SampleTable.cpp index 092c33e..a9163fc 100644 --- a/media/libstagefright/SampleTable.cpp +++ b/media/libstagefright/SampleTable.cpp @@ -76,7 +76,7 @@ SampleTable::~SampleTable() { } status_t SampleTable::setChunkOffsetParams( - uint32_t type, off_t data_offset, size_t data_size) { + uint32_t type, off64_t data_offset, size_t data_size) { if (mChunkOffsetOffset >= 0) { return ERROR_MALFORMED; } @@ -117,7 +117,7 @@ status_t SampleTable::setChunkOffsetParams( } status_t SampleTable::setSampleToChunkParams( - off_t data_offset, size_t data_size) { + off64_t data_offset, size_t data_size) { if (mSampleToChunkOffset >= 0) { return ERROR_MALFORMED; } @@ -168,7 +168,7 @@ status_t SampleTable::setSampleToChunkParams( } status_t SampleTable::setSampleSizeParams( - uint32_t type, off_t data_offset, size_t data_size) { + uint32_t type, off64_t data_offset, size_t data_size) { if (mSampleSizeOffset >= 0) { return ERROR_MALFORMED; } @@ -228,7 +228,7 @@ status_t SampleTable::setSampleSizeParams( } status_t SampleTable::setTimeToSampleParams( - off_t data_offset, size_t data_size) { + off64_t data_offset, size_t data_size) { if (mTimeToSample != NULL || data_size < 8) { return ERROR_MALFORMED; } @@ -260,7 +260,7 @@ status_t SampleTable::setTimeToSampleParams( return OK; } -status_t SampleTable::setSyncSampleParams(off_t data_offset, size_t data_size) { +status_t SampleTable::setSyncSampleParams(off64_t data_offset, size_t data_size) { if (mSyncSampleOffset >= 0 || data_size < 8) { return ERROR_MALFORMED; } @@ -419,8 +419,10 @@ status_t SampleTable::findSyncSampleNear( ++left; } + if (left > 0) { + --left; + } - --left; uint32_t x; if (mDataSource->readAt( mSyncSampleOffset + 8 + left * 4, &x, 4) != 4) { @@ -557,7 +559,7 @@ status_t SampleTable::getSampleSize_l( status_t SampleTable::getMetaDataForSample( uint32_t sampleIndex, - off_t *offset, + off64_t *offset, size_t *size, uint32_t *decodingTime, bool *isSyncSample) { diff --git a/media/libstagefright/ShoutcastSource.cpp b/media/libstagefright/ShoutcastSource.cpp index 23b7681..783f2d0 100644 --- a/media/libstagefright/ShoutcastSource.cpp +++ b/media/libstagefright/ShoutcastSource.cpp @@ -14,7 +14,6 @@ * limitations under the License. */ -#include "include/stagefright_string.h" #include "include/HTTPStream.h" #include <stdlib.h> @@ -34,7 +33,7 @@ ShoutcastSource::ShoutcastSource(HTTPStream *http) mBytesUntilMetaData(0), mGroup(NULL), mStarted(false) { - string metaint; + AString metaint; if (mHttp->find_header_value("icy-metaint", &metaint)) { char *end; const char *start = metaint.c_str(); diff --git a/media/libstagefright/StagefrightMediaScanner.cpp b/media/libstagefright/StagefrightMediaScanner.cpp index 6c05e03..86e0e73 100644 --- a/media/libstagefright/StagefrightMediaScanner.cpp +++ b/media/libstagefright/StagefrightMediaScanner.cpp @@ -127,10 +127,11 @@ status_t StagefrightMediaScanner::processFile( || !strcasecmp(extension, ".rtttl") || !strcasecmp(extension, ".rtx") || !strcasecmp(extension, ".ota")) { - return HandleMIDI(path, &client); - } - - if (mRetriever->setDataSource(path) == OK + status_t status = HandleMIDI(path, &client); + if (status != OK) { + return status; + } + } else if (mRetriever->setDataSource(path) == OK && mRetriever->setMode( METADATA_MODE_METADATA_RETRIEVAL_ONLY) == OK) { const char *value; @@ -174,11 +175,11 @@ status_t StagefrightMediaScanner::processFile( char *StagefrightMediaScanner::extractAlbumArt(int fd) { LOGV("extractAlbumArt %d", fd); - off_t size = lseek(fd, 0, SEEK_END); + off64_t size = lseek64(fd, 0, SEEK_END); if (size < 0) { return NULL; } - lseek(fd, 0, SEEK_SET); + lseek64(fd, 0, SEEK_SET); if (mRetriever->setDataSource(fd, 0, size) == OK && mRetriever->setMode( diff --git a/media/libstagefright/ThrottledSource.cpp b/media/libstagefright/ThrottledSource.cpp index 4711f7c..88e07b0 100644 --- a/media/libstagefright/ThrottledSource.cpp +++ b/media/libstagefright/ThrottledSource.cpp @@ -41,7 +41,7 @@ status_t ThrottledSource::initCheck() const { return mSource->initCheck(); } -ssize_t ThrottledSource::readAt(off_t offset, void *data, size_t size) { +ssize_t ThrottledSource::readAt(off64_t offset, void *data, size_t size) { Mutex::Autolock autoLock(mLock); ssize_t n = mSource->readAt(offset, data, size); @@ -72,7 +72,7 @@ ssize_t ThrottledSource::readAt(off_t offset, void *data, size_t size) { return n; } -status_t ThrottledSource::getSize(off_t *size) { +status_t ThrottledSource::getSize(off64_t *size) { return mSource->getSize(size); } diff --git a/media/libstagefright/VBRISeeker.cpp b/media/libstagefright/VBRISeeker.cpp index 6608644..48bddc2 100644 --- a/media/libstagefright/VBRISeeker.cpp +++ b/media/libstagefright/VBRISeeker.cpp @@ -34,8 +34,8 @@ static uint32_t U24_AT(const uint8_t *ptr) { // static sp<VBRISeeker> VBRISeeker::CreateFromSource( - const sp<DataSource> &source, off_t post_id3_pos) { - off_t pos = post_id3_pos; + const sp<DataSource> &source, off64_t post_id3_pos) { + off64_t pos = post_id3_pos; uint8_t header[4]; ssize_t n = source->readAt(pos, header, sizeof(header)); @@ -94,7 +94,7 @@ sp<VBRISeeker> VBRISeeker::CreateFromSource( seeker->mBasePos = post_id3_pos; seeker->mDurationUs = durationUs; - off_t offset = post_id3_pos; + off64_t offset = post_id3_pos; for (size_t i = 0; i < numEntries; ++i) { uint32_t numBytes; switch (entrySize) { @@ -138,7 +138,7 @@ bool VBRISeeker::getDuration(int64_t *durationUs) { return true; } -bool VBRISeeker::getOffsetForTime(int64_t *timeUs, off_t *pos) { +bool VBRISeeker::getOffsetForTime(int64_t *timeUs, off64_t *pos) { if (mDurationUs < 0) { return false; } diff --git a/media/libstagefright/WAVExtractor.cpp b/media/libstagefright/WAVExtractor.cpp index aff06bc..446021c 100644 --- a/media/libstagefright/WAVExtractor.cpp +++ b/media/libstagefright/WAVExtractor.cpp @@ -51,7 +51,7 @@ struct WAVSource : public MediaSource { const sp<MetaData> &meta, uint16_t waveFormat, int32_t bitsPerSample, - off_t offset, size_t size); + off64_t offset, size_t size); virtual status_t start(MetaData *params = NULL); virtual status_t stop(); @@ -72,11 +72,11 @@ private: int32_t mSampleRate; int32_t mNumChannels; int32_t mBitsPerSample; - off_t mOffset; + off64_t mOffset; size_t mSize; bool mStarted; MediaBufferGroup *mGroup; - off_t mCurrentPos; + off64_t mCurrentPos; WAVSource(const WAVSource &); WAVSource &operator=(const WAVSource &); @@ -139,7 +139,7 @@ status_t WAVExtractor::init() { size_t totalSize = U32_LE_AT(&header[4]); - off_t offset = 12; + off64_t offset = 12; size_t remainingSize = totalSize; while (remainingSize >= 8) { uint8_t chunkHeader[8]; @@ -251,7 +251,7 @@ WAVSource::WAVSource( const sp<MetaData> &meta, uint16_t waveFormat, int32_t bitsPerSample, - off_t offset, size_t size) + off64_t offset, size_t size) : mDataSource(dataSource), mMeta(meta), mWaveFormat(waveFormat), @@ -335,7 +335,7 @@ status_t WAVSource::read( mBitsPerSample == 8 ? kMaxFrameSize / 2 : kMaxFrameSize; size_t maxBytesAvailable = - (mCurrentPos - mOffset >= (off_t)mSize) + (mCurrentPos - mOffset >= (off64_t)mSize) ? 0 : mSize - (mCurrentPos - mOffset); if (maxBytesToRead > maxBytesAvailable) { diff --git a/media/libstagefright/XINGSeeker.cpp b/media/libstagefright/XINGSeeker.cpp index 72f260e..616836c 100644 --- a/media/libstagefright/XINGSeeker.cpp +++ b/media/libstagefright/XINGSeeker.cpp @@ -22,14 +22,14 @@ namespace android { static bool parse_xing_header( - const sp<DataSource> &source, off_t first_frame_pos, + const sp<DataSource> &source, off64_t first_frame_pos, int32_t *frame_number = NULL, int32_t *byte_number = NULL, char *table_of_contents = NULL, int32_t *quality_indicator = NULL, int64_t *duration = NULL); // static sp<XINGSeeker> XINGSeeker::CreateFromSource( - const sp<DataSource> &source, off_t first_frame_pos) { + const sp<DataSource> &source, off64_t first_frame_pos) { sp<XINGSeeker> seeker = new XINGSeeker; seeker->mFirstFramePos = first_frame_pos; @@ -61,7 +61,7 @@ bool XINGSeeker::getDuration(int64_t *durationUs) { return true; } -bool XINGSeeker::getOffsetForTime(int64_t *timeUs, off_t *pos) { +bool XINGSeeker::getOffsetForTime(int64_t *timeUs, off64_t *pos) { if (mSizeBytes == 0 || mTableOfContents[0] <= 0 || mDurationUs < 0) { return false; } @@ -94,7 +94,7 @@ bool XINGSeeker::getOffsetForTime(int64_t *timeUs, off_t *pos) { } static bool parse_xing_header( - const sp<DataSource> &source, off_t first_frame_pos, + const sp<DataSource> &source, off64_t first_frame_pos, int32_t *frame_number, int32_t *byte_number, char *table_of_contents, int32_t *quality_indicator, int64_t *duration) { diff --git a/media/libstagefright/httplive/LiveSource.cpp b/media/libstagefright/httplive/LiveSource.cpp index c19b6f7..4b4c3d2 100644 --- a/media/libstagefright/httplive/LiveSource.cpp +++ b/media/libstagefright/httplive/LiveSource.cpp @@ -447,11 +447,11 @@ bool LiveSource::setupCipher() { static const ssize_t kHeaderSize = 188; -ssize_t LiveSource::readAt(off_t offset, void *data, size_t size) { +ssize_t LiveSource::readAt(off64_t offset, void *data, size_t size) { CHECK(offset >= mOffsetBias); offset -= mOffsetBias; - off_t delta = mSignalDiscontinuity ? kHeaderSize : 0; + off64_t delta = mSignalDiscontinuity ? kHeaderSize : 0; if (offset >= mSourceSize + delta) { CHECK_EQ(offset, mSourceSize + delta); @@ -502,7 +502,7 @@ ssize_t LiveSource::readAt(off_t offset, void *data, size_t size) { mAESIVec, AES_DECRYPT); - if (mSourceSize == (off_t)(offset + numRead - delta + n)) { + if (mSourceSize == (off64_t)(offset + numRead - delta + n)) { // check for padding at the end of the file. size_t pad = tmp->data()[n - 1]; @@ -551,7 +551,7 @@ status_t LiveSource::fetchM3U(const char *url, sp<ABuffer> *out) { source = mSource; } - off_t size; + off64_t size; status_t err = source->getSize(&size); if (err != OK) { diff --git a/media/libstagefright/id3/ID3.cpp b/media/libstagefright/id3/ID3.cpp index da340f7..e9131a6 100644 --- a/media/libstagefright/id3/ID3.cpp +++ b/media/libstagefright/id3/ID3.cpp @@ -769,8 +769,8 @@ ID3::getAlbumArt(size_t *length, String8 *mime) const { bool ID3::parseV1(const sp<DataSource> &source) { const size_t V1_TAG_SIZE = 128; - off_t size; - if (source->getSize(&size) != OK || size < (off_t)V1_TAG_SIZE) { + off64_t size; + if (source->getSize(&size) != OK || size < (off64_t)V1_TAG_SIZE) { return false; } diff --git a/media/libstagefright/include/HTTPStream.h b/media/libstagefright/include/HTTPStream.h index 793798f..545cd0c 100644 --- a/media/libstagefright/include/HTTPStream.h +++ b/media/libstagefright/include/HTTPStream.h @@ -18,10 +18,9 @@ #define HTTP_STREAM_H_ -#include "stagefright_string.h" - #include <sys/types.h> +#include <media/stagefright/foundation/AString.h> #include <media/stagefright/MediaErrors.h> #include <utils/KeyedVector.h> #include <utils/threads.h> @@ -50,7 +49,7 @@ public: static const char *kStatusKey; bool find_header_value( - const string &key, string *value) const; + const AString &key, AString *value) const; // Pass a negative value to disable the timeout. void setReceiveTimeout(int seconds); @@ -70,7 +69,7 @@ private: Mutex mLock; int mSocket; - KeyedVector<string, string> mHeaders; + KeyedVector<AString, AString> mHeaders; HTTPStream(const HTTPStream &); HTTPStream &operator=(const HTTPStream &); diff --git a/media/libstagefright/include/LiveSource.h b/media/libstagefright/include/LiveSource.h index 7ba1f44..38fe328 100644 --- a/media/libstagefright/include/LiveSource.h +++ b/media/libstagefright/include/LiveSource.h @@ -35,7 +35,7 @@ struct LiveSource : public DataSource { virtual status_t initCheck() const; - virtual ssize_t readAt(off_t offset, void *data, size_t size); + virtual ssize_t readAt(off64_t offset, void *data, size_t size); virtual uint32_t flags() { return kWantsPrefetching; @@ -67,8 +67,8 @@ private: int64_t mLastFetchTimeUs; sp<NuHTTPDataSource> mSource; - off_t mSourceSize; - off_t mOffsetBias; + off64_t mSourceSize; + off64_t mOffsetBias; bool mSignalDiscontinuity; ssize_t mPrevBandwidthIndex; diff --git a/media/libstagefright/include/MP3Extractor.h b/media/libstagefright/include/MP3Extractor.h index 11ca243..728980e 100644 --- a/media/libstagefright/include/MP3Extractor.h +++ b/media/libstagefright/include/MP3Extractor.h @@ -47,7 +47,7 @@ private: status_t mInitCheck; sp<DataSource> mDataSource; - off_t mFirstFramePos; + off64_t mFirstFramePos; sp<MetaData> mMeta; uint32_t mFixedHeader; sp<MP3Seeker> mSeeker; diff --git a/media/libstagefright/include/MP3Seeker.h b/media/libstagefright/include/MP3Seeker.h index 190eaed..599542e 100644 --- a/media/libstagefright/include/MP3Seeker.h +++ b/media/libstagefright/include/MP3Seeker.h @@ -31,7 +31,7 @@ struct MP3Seeker : public RefBase { // Given a request seek time in "*timeUs", find the byte offset closest // to that position and return it in "*pos". Update "*timeUs" to reflect // the actual time that seekpoint represents. - virtual bool getOffsetForTime(int64_t *timeUs, off_t *pos) = 0; + virtual bool getOffsetForTime(int64_t *timeUs, off64_t *pos) = 0; protected: virtual ~MP3Seeker() {} diff --git a/media/libstagefright/include/MPEG2TSExtractor.h b/media/libstagefright/include/MPEG2TSExtractor.h index d83b538..58401d4 100644 --- a/media/libstagefright/include/MPEG2TSExtractor.h +++ b/media/libstagefright/include/MPEG2TSExtractor.h @@ -43,7 +43,7 @@ private: Vector<sp<AnotherPacketSource> > mSourceImpls; - off_t mOffset; + off64_t mOffset; void init(); status_t feedMore(); diff --git a/media/libstagefright/include/MPEG4Extractor.h b/media/libstagefright/include/MPEG4Extractor.h index bc2e4dc..04e8a6a 100644 --- a/media/libstagefright/include/MPEG4Extractor.h +++ b/media/libstagefright/include/MPEG4Extractor.h @@ -67,8 +67,8 @@ private: Vector<uint32_t> mPath; status_t readMetaData(); - status_t parseChunk(off_t *offset, int depth); - status_t parseMetaData(off_t offset, size_t size); + status_t parseChunk(off64_t *offset, int depth); + status_t parseMetaData(off64_t offset, size_t size); status_t updateAudioTrackInfoFromESDS_MPEG4Audio( const void *esds_data, size_t esds_size); @@ -86,9 +86,9 @@ private: SINF *mFirstSINF; bool mIsDrm; - status_t parseDrmSINF(off_t *offset, off_t data_offset); + status_t parseDrmSINF(off64_t *offset, off64_t data_offset); - status_t parseTrackHeader(off_t data_offset, off_t data_size); + status_t parseTrackHeader(off64_t data_offset, off64_t data_size); MPEG4Extractor(const MPEG4Extractor &); MPEG4Extractor &operator=(const MPEG4Extractor &); diff --git a/media/libstagefright/include/NuCachedSource2.h b/media/libstagefright/include/NuCachedSource2.h index 5e404b6..f0f7daf 100644 --- a/media/libstagefright/include/NuCachedSource2.h +++ b/media/libstagefright/include/NuCachedSource2.h @@ -32,9 +32,9 @@ struct NuCachedSource2 : public DataSource { virtual status_t initCheck() const; - virtual ssize_t readAt(off_t offset, void *data, size_t size); + virtual ssize_t readAt(off64_t offset, void *data, size_t size); - virtual status_t getSize(off_t *size); + virtual status_t getSize(off64_t *size); virtual uint32_t flags(); virtual DecryptHandle* DrmInitialization(DrmManagerClient *client); @@ -81,9 +81,9 @@ private: Condition mCondition; PageCache *mCache; - off_t mCacheOffset; + off64_t mCacheOffset; status_t mFinalStatus; - off_t mLastAccessPos; + off64_t mLastAccessPos; sp<AMessage> mAsyncResult; bool mFetching; int64_t mLastFetchTimeUs; @@ -95,8 +95,8 @@ private: void onSuspend(); void fetchInternal(); - ssize_t readInternal(off_t offset, void *data, size_t size); - status_t seekInternal_l(off_t offset); + ssize_t readInternal(off64_t offset, void *data, size_t size); + status_t seekInternal_l(off64_t offset); size_t approxDataRemaining_l(bool *eos); void restartPrefetcherIfNecessary_l(bool ignoreLowWaterThreshold = false); diff --git a/media/libstagefright/include/NuHTTPDataSource.h b/media/libstagefright/include/NuHTTPDataSource.h index c42691f..c8e93be 100644 --- a/media/libstagefright/include/NuHTTPDataSource.h +++ b/media/libstagefright/include/NuHTTPDataSource.h @@ -17,14 +17,14 @@ struct NuHTTPDataSource : public DataSource { status_t connect( const char *uri, const KeyedVector<String8, String8> *headers = NULL, - off_t offset = 0); + off64_t offset = 0); void disconnect(); virtual status_t initCheck() const; - virtual ssize_t readAt(off_t offset, void *data, size_t size); - virtual status_t getSize(off_t *size); + virtual ssize_t readAt(off64_t offset, void *data, size_t size); + virtual status_t getSize(off64_t *size); virtual uint32_t flags(); // Returns true if bandwidth could successfully be estimated, @@ -61,8 +61,8 @@ private: String8 mUri; HTTPStream mHTTP; - off_t mOffset; - off_t mContentLength; + off64_t mOffset; + off64_t mContentLength; bool mContentLengthValid; bool mHasChunkedTransferEncoding; @@ -79,12 +79,12 @@ private: DrmManagerClient *mDrmManagerClient; status_t connect( - const char *uri, const String8 &headers, off_t offset); + const char *uri, const String8 &headers, off64_t offset); status_t connect( const char *host, unsigned port, const char *path, const String8 &headers, - off_t offset); + off64_t offset); // Read up to "size" bytes of data, respect transfer encoding. ssize_t internalRead(void *data, size_t size); diff --git a/media/libstagefright/include/SampleIterator.h b/media/libstagefright/include/SampleIterator.h index a5eaed9..b5a043c 100644 --- a/media/libstagefright/include/SampleIterator.h +++ b/media/libstagefright/include/SampleIterator.h @@ -27,7 +27,7 @@ struct SampleIterator { uint32_t getChunkIndex() const { return mCurrentChunkIndex; } uint32_t getDescIndex() const { return mChunkDesc; } - off_t getSampleOffset() const { return mCurrentSampleOffset; } + off64_t getSampleOffset() const { return mCurrentSampleOffset; } size_t getSampleSize() const { return mCurrentSampleSize; } uint32_t getSampleTime() const { return mCurrentSampleTime; } @@ -48,7 +48,7 @@ private: uint32_t mChunkDesc; uint32_t mCurrentChunkIndex; - off_t mCurrentChunkOffset; + off64_t mCurrentChunkOffset; Vector<size_t> mCurrentChunkSampleSizes; uint32_t mTimeToSampleIndex; @@ -58,13 +58,13 @@ private: uint32_t mTTSDuration; uint32_t mCurrentSampleIndex; - off_t mCurrentSampleOffset; + off64_t mCurrentSampleOffset; size_t mCurrentSampleSize; uint32_t mCurrentSampleTime; void reset(); status_t findChunkRange(uint32_t sampleIndex); - status_t getChunkOffset(uint32_t chunk, off_t *offset); + status_t getChunkOffset(uint32_t chunk, off64_t *offset); status_t findSampleTime(uint32_t sampleIndex, uint32_t *time); SampleIterator(const SampleIterator &); diff --git a/media/libstagefright/include/SampleTable.h b/media/libstagefright/include/SampleTable.h index f830690..c5e8136 100644 --- a/media/libstagefright/include/SampleTable.h +++ b/media/libstagefright/include/SampleTable.h @@ -36,17 +36,17 @@ public: // type can be 'stco' or 'co64'. status_t setChunkOffsetParams( - uint32_t type, off_t data_offset, size_t data_size); + uint32_t type, off64_t data_offset, size_t data_size); - status_t setSampleToChunkParams(off_t data_offset, size_t data_size); + status_t setSampleToChunkParams(off64_t data_offset, size_t data_size); // type can be 'stsz' or 'stz2'. status_t setSampleSizeParams( - uint32_t type, off_t data_offset, size_t data_size); + uint32_t type, off64_t data_offset, size_t data_size); - status_t setTimeToSampleParams(off_t data_offset, size_t data_size); + status_t setTimeToSampleParams(off64_t data_offset, size_t data_size); - status_t setSyncSampleParams(off_t data_offset, size_t data_size); + status_t setSyncSampleParams(off64_t data_offset, size_t data_size); //////////////////////////////////////////////////////////////////////////// @@ -58,7 +58,7 @@ public: status_t getMetaDataForSample( uint32_t sampleIndex, - off_t *offset, + off64_t *offset, size_t *size, uint32_t *decodingTime, bool *isSyncSample = NULL); @@ -89,14 +89,14 @@ private: sp<DataSource> mDataSource; Mutex mLock; - off_t mChunkOffsetOffset; + off64_t mChunkOffsetOffset; uint32_t mChunkOffsetType; uint32_t mNumChunkOffsets; - off_t mSampleToChunkOffset; + off64_t mSampleToChunkOffset; uint32_t mNumSampleToChunkOffsets; - off_t mSampleSizeOffset; + off64_t mSampleSizeOffset; uint32_t mSampleSizeFieldSize; uint32_t mDefaultSampleSize; uint32_t mNumSampleSizes; @@ -104,7 +104,7 @@ private: uint32_t mTimeToSampleCount; uint32_t *mTimeToSample; - off_t mSyncSampleOffset; + off64_t mSyncSampleOffset; uint32_t mNumSyncSamples; uint32_t *mSyncSamples; size_t mLastSyncSampleIndex; diff --git a/media/libstagefright/include/ThrottledSource.h b/media/libstagefright/include/ThrottledSource.h index 88164b3..8928a4a 100644 --- a/media/libstagefright/include/ThrottledSource.h +++ b/media/libstagefright/include/ThrottledSource.h @@ -30,9 +30,9 @@ struct ThrottledSource : public DataSource { virtual status_t initCheck() const; - virtual ssize_t readAt(off_t offset, void *data, size_t size); + virtual ssize_t readAt(off64_t offset, void *data, size_t size); - virtual status_t getSize(off_t *size); + virtual status_t getSize(off64_t *size); virtual uint32_t flags(); private: diff --git a/media/libstagefright/include/VBRISeeker.h b/media/libstagefright/include/VBRISeeker.h index d6bd19d..1a2bf9f 100644 --- a/media/libstagefright/include/VBRISeeker.h +++ b/media/libstagefright/include/VBRISeeker.h @@ -28,13 +28,13 @@ struct DataSource; struct VBRISeeker : public MP3Seeker { static sp<VBRISeeker> CreateFromSource( - const sp<DataSource> &source, off_t post_id3_pos); + const sp<DataSource> &source, off64_t post_id3_pos); virtual bool getDuration(int64_t *durationUs); - virtual bool getOffsetForTime(int64_t *timeUs, off_t *pos); + virtual bool getOffsetForTime(int64_t *timeUs, off64_t *pos); private: - off_t mBasePos; + off64_t mBasePos; int64_t mDurationUs; Vector<uint32_t> mSegments; diff --git a/media/libstagefright/include/WAVExtractor.h b/media/libstagefright/include/WAVExtractor.h index df6d3e7..9de197f 100644 --- a/media/libstagefright/include/WAVExtractor.h +++ b/media/libstagefright/include/WAVExtractor.h @@ -48,7 +48,7 @@ private: uint16_t mNumChannels; uint32_t mSampleRate; uint16_t mBitsPerSample; - off_t mDataOffset; + off64_t mDataOffset; size_t mDataSize; sp<MetaData> mTrackMeta; diff --git a/media/libstagefright/include/XINGSeeker.h b/media/libstagefright/include/XINGSeeker.h index d4ff4e1..d5a484e 100644 --- a/media/libstagefright/include/XINGSeeker.h +++ b/media/libstagefright/include/XINGSeeker.h @@ -26,10 +26,10 @@ struct DataSource; struct XINGSeeker : public MP3Seeker { static sp<XINGSeeker> CreateFromSource( - const sp<DataSource> &source, off_t first_frame_pos); + const sp<DataSource> &source, off64_t first_frame_pos); virtual bool getDuration(int64_t *durationUs); - virtual bool getOffsetForTime(int64_t *timeUs, off_t *pos); + virtual bool getOffsetForTime(int64_t *timeUs, off64_t *pos); private: int64_t mFirstFramePos; diff --git a/media/libstagefright/include/stagefright_string.h b/media/libstagefright/include/stagefright_string.h deleted file mode 100644 index 5dc7116..0000000 --- a/media/libstagefright/include/stagefright_string.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2009 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 STRING_H_ - -#define STRING_H_ - -#include <utils/String8.h> - -namespace android { - -class string { -public: - typedef size_t size_type; - static size_type npos; - - string(); - string(const char *s); - string(const char *s, size_t length); - string(const string &from, size_type start, size_type length = npos); - - const char *c_str() const; - size_type size() const; - - void clear(); - void erase(size_type from, size_type length); - - size_type find(char c) const; - - bool operator<(const string &other) const; - bool operator==(const string &other) const; - - string &operator+=(char c); - -private: - String8 mString; -}; - -} // namespace android - -#endif // STRING_H_ diff --git a/media/libstagefright/matroska/MatroskaExtractor.cpp b/media/libstagefright/matroska/MatroskaExtractor.cpp index a40c0a3..e0ac49f 100644 --- a/media/libstagefright/matroska/MatroskaExtractor.cpp +++ b/media/libstagefright/matroska/MatroskaExtractor.cpp @@ -58,7 +58,7 @@ struct DataSourceReader : public mkvparser::IMkvReader { } virtual int Length(long long* total, long long* available) { - off_t size; + off64_t size; if (mSource->getSize(&size) != OK) { return -1; } diff --git a/media/libstagefright/rtsp/ARTPWriter.cpp b/media/libstagefright/rtsp/ARTPWriter.cpp index 155fd96..5a033e1 100644 --- a/media/libstagefright/rtsp/ARTPWriter.cpp +++ b/media/libstagefright/rtsp/ARTPWriter.cpp @@ -46,7 +46,7 @@ static int UniformRand(int limit) { ARTPWriter::ARTPWriter(int fd) : mFlags(0), - mFd(fd), + mFd(dup(fd)), mLooper(new ALooper), mReflector(new AHandlerReflector<ARTPWriter>(this)) { CHECK_GE(fd, 0); diff --git a/media/libstagefright/string.cpp b/media/libstagefright/string.cpp deleted file mode 100644 index 8b2c36c..0000000 --- a/media/libstagefright/string.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (C) 2009 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/stagefright_string.h" - -#include <media/stagefright/MediaDebug.h> - -namespace android { - -// static -string::size_type string::npos = (string::size_type)-1; - -string::string() { -} - -string::string(const char *s, size_t length) - : mString(s, length) { -} - -string::string(const string &from, size_type start, size_type length) { - CHECK(start <= from.size()); - if (length == npos) { - length = from.size() - start; - } else { - CHECK(start + length <= from.size()); - } - - mString.setTo(from.c_str() + start, length); -} - -string::string(const char *s) - : mString(s) { -} - -const char *string::c_str() const { - return mString.string(); -} - -string::size_type string::size() const { - return mString.length(); -} - -void string::clear() { - mString = String8(); -} - -string::size_type string::find(char c) const { - char s[2]; - s[0] = c; - s[1] = '\0'; - - ssize_t index = mString.find(s); - - return index < 0 ? npos : (size_type)index; -} - -bool string::operator<(const string &other) const { - return mString < other.mString; -} - -bool string::operator==(const string &other) const { - return mString == other.mString; -} - -string &string::operator+=(char c) { - mString.append(&c, 1); - - return *this; -} - -void string::erase(size_t from, size_t length) { - String8 s(mString.string(), from); - s.append(mString.string() + from + length); - - mString = s; -} - -} // namespace android - diff --git a/media/mtp/MtpDataPacket.cpp b/media/mtp/MtpDataPacket.cpp index 20dd94d..e1d1a92 100644 --- a/media/mtp/MtpDataPacket.cpp +++ b/media/mtp/MtpDataPacket.cpp @@ -413,20 +413,32 @@ int MtpDataPacket::read(struct usb_endpoint *ep) { } int MtpDataPacket::readData(struct usb_endpoint *ep, void* buffer, int length) { - int packetSize = usb_endpoint_max_packet(ep); int read = 0; while (read < length) { - int ret = transfer(ep, (char *)buffer + read, packetSize); + int ret = transfer(ep, (char *)buffer + read, length - read); if (ret < 0) { -printf("MtpDataPacket::readData returning %d\n", ret); return ret; } read += ret; } -printf("MtpDataPacket::readData returning %d\n", read); return read; } +// Queue a read request. Call readDataWait to wait for result +int MtpDataPacket::readDataAsync(struct usb_endpoint *ep, void* buffer, int length) { + if (usb_endpoint_queue(ep, buffer, length)) { + LOGE("usb_endpoint_queue failed, errno: %d", errno); + return -1; + } + return 0; +} + +// Wait for result of readDataAsync +int MtpDataPacket::readDataWait(struct usb_endpoint *ep) { + int ep_num; + return usb_endpoint_wait(usb_endpoint_get_device(ep), &ep_num); +} + int MtpDataPacket::readDataHeader(struct usb_endpoint *ep) { int length = transfer(ep, mBuffer, usb_endpoint_max_packet(ep)); if (length >= 0) @@ -454,15 +466,7 @@ int MtpDataPacket::write(struct usb_endpoint *ep) { } int MtpDataPacket::write(struct usb_endpoint *ep, void* buffer, uint32_t length) { - int ret = 0; - int packetSize = usb_endpoint_max_packet(ep); - while (length > 0) { - int write = (length > packetSize ? packetSize : length); - int ret = transfer(ep, buffer, write); - if (ret < 0) - break; - length -= ret; - } + int ret = transfer(ep, buffer, length); return (ret < 0 ? ret : 0); } diff --git a/media/mtp/MtpDataPacket.h b/media/mtp/MtpDataPacket.h index fab6a07..3ae6226 100644 --- a/media/mtp/MtpDataPacket.h +++ b/media/mtp/MtpDataPacket.h @@ -102,6 +102,8 @@ public: #ifdef MTP_HOST int read(struct usb_endpoint *ep); int readData(struct usb_endpoint *ep, void* buffer, int length); + int readDataAsync(struct usb_endpoint *ep, void* buffer, int length); + int readDataWait(struct usb_endpoint *ep); int readDataHeader(struct usb_endpoint *ep); int writeDataHeader(struct usb_endpoint *ep, uint32_t length); @@ -110,6 +112,7 @@ public: #endif inline bool hasData() const { return mPacketSize > MTP_CONTAINER_HEADER_SIZE; } + inline uint32_t getContainerLength() const { return MtpPacket::getUInt32(MTP_CONTAINER_LENGTH_OFFSET); } void* getData(int& outLength) const; }; diff --git a/media/mtp/MtpDevice.cpp b/media/mtp/MtpDevice.cpp index fca0142..416ebfe 100644 --- a/media/mtp/MtpDevice.cpp +++ b/media/mtp/MtpDevice.cpp @@ -348,97 +348,96 @@ MtpProperty* MtpDevice::getDevicePropDesc(MtpDeviceProperty code) { return NULL; } -class ReadObjectThread : public Thread { -private: - MtpDevice* mDevice; - MtpObjectHandle mHandle; - int mObjectSize; - void* mInitialData; - int mInitialDataLength; - int mFD; - -public: - ReadObjectThread(MtpDevice* device, MtpObjectHandle handle, int objectSize) - : mDevice(device), - mHandle(handle), - mObjectSize(objectSize), - mInitialData(NULL), - mInitialDataLength(0) - { +// reads the object's data and writes it to the specified file path +bool MtpDevice::readObject(MtpObjectHandle handle, const char* destPath, int group, int perm) { + LOGD("readObject: %s", destPath); + int fd = ::open(destPath, O_RDWR | O_CREAT | O_TRUNC); + if (fd < 0) { + LOGE("open failed for %s", destPath); + return false; } - virtual ~ReadObjectThread() { - if (mFD >= 0) - close(mFD); - free(mInitialData); - } + fchown(fd, getuid(), group); + // set permissions + int mask = umask(0); + fchmod(fd, perm); + umask(mask); - // returns file descriptor - int init() { - mDevice->mRequest.reset(); - mDevice->mRequest.setParameter(1, mHandle); - if (mDevice->sendRequest(MTP_OPERATION_GET_OBJECT) - && mDevice->mData.readDataHeader(mDevice->mEndpointIn)) { - - // mData will contain header and possibly the beginning of the object data - mInitialData = mDevice->mData.getData(mInitialDataLength); - - // create a pipe for the client to read from - int pipefd[2]; - if (pipe(pipefd) < 0) { - LOGE("pipe failed (%s)", strerror(errno)); - return -1; - } - - mFD = pipefd[1]; - return pipefd[0]; - } else { - return -1; - } - } + Mutex::Autolock autoLock(mMutex); + bool result = false; - virtual bool threadLoop() { - int remaining = mObjectSize; - if (mInitialData) { - write(mFD, mInitialData, mInitialDataLength); - remaining -= mInitialDataLength; - free(mInitialData); - mInitialData = NULL; + mRequest.reset(); + mRequest.setParameter(1, handle); + if (sendRequest(MTP_OPERATION_GET_OBJECT) + && mData.readDataHeader(mEndpointIn)) { + uint32_t length = mData.getContainerLength(); + if (length < MTP_CONTAINER_HEADER_SIZE) + goto fail; + length -= MTP_CONTAINER_HEADER_SIZE; + uint32_t remaining = length; + + int initialDataLength = 0; + void* initialData = mData.getData(initialDataLength); + if (initialData) { + if (initialDataLength > 0) { + if (write(fd, initialData, initialDataLength) != initialDataLength) + goto fail; + remaining -= initialDataLength; + } + free(initialData); } - char buffer[16384]; - while (remaining > 0) { - int readSize = (remaining > sizeof(buffer) ? sizeof(buffer) : remaining); - int count = mDevice->mData.readData(mDevice->mEndpointIn, buffer, readSize); - int written; - if (count >= 0) { - int written = write(mFD, buffer, count); - // FIXME check error - remaining -= count; + // USB reads greater than 16K don't work + char buffer1[16384], buffer2[16384]; + char* readBuffer = buffer1; + char* writeBuffer = NULL; + int writeLength = 0; + + while (remaining > 0 || writeBuffer) { + if (remaining > 0) { + // queue up a read request + int readSize = (remaining > sizeof(buffer1) ? sizeof(buffer1) : remaining); + if (mData.readDataAsync(mEndpointIn, readBuffer, readSize)) { + LOGE("readDataAsync failed"); + goto fail; + } } else { - break; + readBuffer = NULL; } - } - MtpResponseCode ret = mDevice->readResponse(); - mDevice->mMutex.unlock(); - return false; - } -}; + if (writeBuffer) { + // write previous buffer + if (write(fd, writeBuffer, writeLength) != writeLength) { + LOGE("write failed"); + // wait for pending read before failing + if (readBuffer) + mData.readDataWait(mEndpointIn); + goto fail; + } + writeBuffer = NULL; + } - // returns the file descriptor for a pipe to read the object's data -int MtpDevice::readObject(MtpObjectHandle handle, int objectSize) { - mMutex.lock(); + // wait for read to complete + if (readBuffer) { + int read = mData.readDataWait(mEndpointIn); + if (read < 0) + goto fail; - ReadObjectThread* thread = new ReadObjectThread(this, handle, objectSize); - int fd = thread->init(); - if (fd < 0) { - delete thread; - mMutex.unlock(); - } else { - thread->run("ReadObjectThread"); + writeBuffer = readBuffer; + writeLength = read; + remaining -= read; + readBuffer = (readBuffer == buffer1 ? buffer2 : buffer1); + } + } + + MtpResponseCode response = readResponse(); + if (response == MTP_RESPONSE_OK) + result = true; } - return fd; + +fail: + ::close(fd); + return result; } bool MtpDevice::sendRequest(MtpOperationCode operation) { diff --git a/media/mtp/MtpDevice.h b/media/mtp/MtpDevice.h index 57f492f..21c85d5 100644 --- a/media/mtp/MtpDevice.h +++ b/media/mtp/MtpDevice.h @@ -75,7 +75,8 @@ public: MtpDeviceInfo* getDeviceInfo(); MtpStorageIDList* getStorageIDs(); MtpStorageInfo* getStorageInfo(MtpStorageID storageID); - MtpObjectHandleList* getObjectHandles(MtpStorageID storageID, MtpObjectFormat format, MtpObjectHandle parent); + MtpObjectHandleList* getObjectHandles(MtpStorageID storageID, MtpObjectFormat format, + MtpObjectHandle parent); MtpObjectInfo* getObjectInfo(MtpObjectHandle handle); void* getThumbnail(MtpObjectHandle handle, int& outLength); MtpObjectHandle sendObjectInfo(MtpObjectInfo* info); @@ -86,12 +87,10 @@ public: MtpProperty* getDevicePropDesc(MtpDeviceProperty code); - // returns the file descriptor for a pipe to read the object's data - int readObject(MtpObjectHandle handle, int objectSize); + bool readObject(MtpObjectHandle handle, const char* destPath, int group, + int perm); private: - friend class ReadObjectThread; - bool sendRequest(MtpOperationCode operation); bool sendData(); bool readData(); diff --git a/media/tests/CameraBrowser/Android.mk b/media/tests/CameraBrowser/Android.mk index 1d81129..295b3e6 100644 --- a/media/tests/CameraBrowser/Android.mk +++ b/media/tests/CameraBrowser/Android.mk @@ -1,7 +1,7 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) -LOCAL_MODULE_TAGS := tests +LOCAL_MODULE_TAGS := optional LOCAL_SRC_FILES := $(call all-subdir-java-files) diff --git a/media/tests/CameraBrowser/AndroidManifest.xml b/media/tests/CameraBrowser/AndroidManifest.xml index eae0b01..db4a336 100644 --- a/media/tests/CameraBrowser/AndroidManifest.xml +++ b/media/tests/CameraBrowser/AndroidManifest.xml @@ -1,8 +1,6 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.camerabrowser"> - <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> - <application android:label="@string/app_label"> <activity android:name="CameraBrowser" android:label="Camera Browser"> <intent-filter> diff --git a/media/tests/CameraBrowser/res/layout/object_info.xml b/media/tests/CameraBrowser/res/layout/object_info.xml index ac210b9..a0499f2 100644 --- a/media/tests/CameraBrowser/res/layout/object_info.xml +++ b/media/tests/CameraBrowser/res/layout/object_info.xml @@ -153,5 +153,17 @@ <TableRow> <ImageView android:id="@+id/thumbnail" /> </TableRow> + <TableRow> + <Button android:id="@+id/import_button" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/import_label"> + </Button> + <Button android:id="@+id/delete_button" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/delete_label"> + </Button> + </TableRow> </TableLayout> diff --git a/media/tests/CameraBrowser/res/menu/object_menu.xml b/media/tests/CameraBrowser/res/menu/object_menu.xml deleted file mode 100644 index a0865f0..0000000 --- a/media/tests/CameraBrowser/res/menu/object_menu.xml +++ /dev/null @@ -1,23 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2010 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. ---> - -<menu xmlns:android="http://schemas.android.com/apk/res/android"> - - <item android:id="@+id/save" - android:title="@string/save_item" /> - <item android:id="@+id/delete" - android:title="@string/delete_item" /> -</menu> diff --git a/media/tests/CameraBrowser/res/values/strings.xml b/media/tests/CameraBrowser/res/values/strings.xml index cd477f1..7955773 100644 --- a/media/tests/CameraBrowser/res/values/strings.xml +++ b/media/tests/CameraBrowser/res/values/strings.xml @@ -32,9 +32,9 @@ <string name="modified_label">Modified: </string> <string name="keywords_label">Keywords: </string> - <!-- menu items --> - <string name="save_item">Save</string> - <string name="delete_item">Delete</string> + <!-- button labels --> + <string name="import_label">Import</string> + <string name="delete_label">Delete</string> <!-- toasts --> <string name="object_saved_message">Object saved</string> diff --git a/media/tests/CameraBrowser/src/com/android/camerabrowser/DeviceDisconnectedReceiver.java b/media/tests/CameraBrowser/src/com/android/camerabrowser/DeviceDisconnectedReceiver.java new file mode 100644 index 0000000..fb004c4 --- /dev/null +++ b/media/tests/CameraBrowser/src/com/android/camerabrowser/DeviceDisconnectedReceiver.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2010 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. + */ + +package com.android.camerabrowser; + +import android.app.Activity; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.hardware.Usb; +import android.net.Uri; + +public class DeviceDisconnectedReceiver extends BroadcastReceiver { + + private final Activity mActivity; + private final int mDeviceID; + + public DeviceDisconnectedReceiver(Activity activity, int deviceID) { + mActivity = activity; + mDeviceID = deviceID; + + IntentFilter filter = new IntentFilter(Usb.ACTION_USB_CAMERA_DETACHED); + filter.addDataScheme("content"); + activity.registerReceiver(this, filter); + } + + @Override + public void onReceive(Context context, Intent intent) { + // close our activity if the device it is displaying is disconnected + Uri uri = intent.getData(); + int id = Integer.parseInt(uri.getPathSegments().get(1)); + if (id == mDeviceID) { + mActivity.finish(); + } + } +}
\ No newline at end of file diff --git a/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectBrowser.java b/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectBrowser.java index 6d34fd4..2060657 100644 --- a/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectBrowser.java +++ b/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectBrowser.java @@ -46,6 +46,7 @@ public class ObjectBrowser extends ListActivity { private int mDeviceID; private long mStorageID; private long mObjectID; + private DeviceDisconnectedReceiver mDisconnectedReceiver; private static final String[] OBJECT_COLUMNS = new String[] { Mtp.Object._ID, Mtp.Object.NAME, Mtp.Object.FORMAT, Mtp.Object.THUMB }; @@ -58,15 +59,17 @@ public class ObjectBrowser extends ListActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + mDeviceID = getIntent().getIntExtra("device", 0); + mStorageID = getIntent().getLongExtra("storage", 0); + mObjectID = getIntent().getLongExtra("object", 0); + mDisconnectedReceiver = new DeviceDisconnectedReceiver(this, mDeviceID); } @Override protected void onResume() { super.onResume(); - mDeviceID = getIntent().getIntExtra("device", 0); - mStorageID = getIntent().getLongExtra("storage", 0); - mObjectID = getIntent().getLongExtra("object", 0); if (mDeviceID != 0 && mStorageID != 0) { Cursor c; Uri uri; @@ -87,6 +90,12 @@ public class ObjectBrowser extends ListActivity { } @Override + protected void onDestroy() { + unregisterReceiver(mDisconnectedReceiver); + super.onDestroy(); + } + + @Override protected void onListItemClick(ListView l, View v, int position, long id) { long rowID = mAdapter.getItemId(position); Cursor c = getContentResolver().query( diff --git a/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectViewer.java b/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectViewer.java index 9f2f98e..4e63128 100644 --- a/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectViewer.java +++ b/media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectViewer.java @@ -16,6 +16,7 @@ package com.android.camerabrowser; import android.app.Activity; +import android.content.ContentValues; import android.content.Intent; import android.database.Cursor; import android.graphics.Bitmap; @@ -23,36 +24,31 @@ import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; import android.os.Environment; -import android.os.FileUtils; -import android.os.ParcelFileDescriptor; -import android.os.Process; import android.provider.Mtp; import android.util.Log; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; import android.view.View; +import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; import java.io.File; -import java.io.FileDescriptor; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.util.Calendar; import java.util.Date; /** * A view to display the properties of an object. */ -public class ObjectViewer extends Activity { +public class ObjectViewer extends Activity implements View.OnClickListener { private static final String TAG = "ObjectViewer"; private int mDeviceID; private long mStorageID; private long mObjectID; + private String mFileName; + private Button mImportButton; + private Button mDeleteButton; + private DeviceDisconnectedReceiver mDisconnectedReceiver; private static final String[] OBJECT_COLUMNS = new String[] { Mtp.Object._ID, @@ -77,15 +73,21 @@ public class ObjectViewer extends Activity { super.onCreate(savedInstanceState); setContentView(R.layout.object_info); - } - @Override - protected void onResume() { - super.onResume(); + mImportButton = (Button)findViewById(R.id.import_button); + mImportButton.setOnClickListener(this); + mDeleteButton = (Button)findViewById(R.id.delete_button); + mDeleteButton.setOnClickListener(this); mDeviceID = getIntent().getIntExtra("device", 0); mStorageID = getIntent().getLongExtra("storage", 0); mObjectID = getIntent().getLongExtra("object", 0); + mDisconnectedReceiver = new DeviceDisconnectedReceiver(this, mDeviceID); + } + + @Override + protected void onResume() { + super.onResume(); if (mDeviceID != 0 && mObjectID != 0) { Cursor c = getContentResolver().query( @@ -93,7 +95,8 @@ public class ObjectViewer extends Activity { OBJECT_COLUMNS, null, null, null); c.moveToFirst(); TextView view = (TextView)findViewById(R.id.name); - view.setText(c.getString(1)); + mFileName = c.getString(1); + view.setText(mFileName); view = (TextView)findViewById(R.id.size); view.setText(Long.toString(c.getLong(2))); view = (TextView)findViewById(R.id.thumb_width); @@ -132,113 +135,33 @@ public class ObjectViewer extends Activity { } @Override - public boolean onCreateOptionsMenu(Menu menu) { - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.object_menu, menu); - return true; - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - MenuItem item = menu.findItem(R.id.save); - item.setEnabled(true); - item = menu.findItem(R.id.delete); - item.setEnabled(true); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.save: - save(); - return true; - case R.id.delete: - delete(); - return true; - } - return false; - } - - private static String getTimestamp() { - Calendar c = Calendar.getInstance(); - c.setTimeInMillis(System.currentTimeMillis()); - return String.format("%tY-%tm-%td-%tH-%tM-%tS", c, c, c, c, c, c); + protected void onDestroy() { + unregisterReceiver(mDisconnectedReceiver); + super.onDestroy(); } - private void save() { - boolean success = false; - Uri uri = Mtp.Object.getContentUri(mDeviceID, mObjectID); - File destFile = null; - ParcelFileDescriptor pfd = null; - FileInputStream fis = null; - FileOutputStream fos = null; - - try { - pfd = getContentResolver().openFileDescriptor(uri, "r"); - Log.d(TAG, "save got pfd " + pfd); - if (pfd != null) { - fis = new FileInputStream(pfd.getFileDescriptor()); - Log.d(TAG, "save got fis " + fis); - File destDir = Environment.getExternalStoragePublicDirectory( - Environment.DIRECTORY_DCIM); - destDir.mkdirs(); - destFile = new File(destDir, "CameraBrowser-" + getTimestamp() + ".jpeg"); - - - Log.d(TAG, "save got destFile " + destFile); - - if (destFile.exists()) { - destFile.delete(); - } - fos = new FileOutputStream(destFile); - - byte[] buffer = new byte[65536]; - int bytesRead; - while ((bytesRead = fis.read(buffer)) >= 0) { - fos.write(buffer, 0, bytesRead); - } + private void importObject() { + // copy file to /mnt/sdcard/imported/<filename> + File dest = Environment.getExternalStorageDirectory(); + dest = new File(dest, "imported"); + dest.mkdirs(); + dest = new File(dest, mFileName); - // temporary workaround until we straighten out permissions in /data/media - FileUtils.setPermissions(destDir.getPath(), 0775, Process.myUid(), Process.SDCARD_RW_GID); - FileUtils.setPermissions(destFile.getPath(), 0664, Process.myUid(), Process.SDCARD_RW_GID); + Uri requestUri = Mtp.Object.getContentUriForImport(mDeviceID, mObjectID, + dest.getAbsolutePath()); + Uri resultUri = getContentResolver().insert(requestUri, new ContentValues()); + Log.d(TAG, "save returned " + resultUri); - success = true; - } - } catch (Exception e) { - Log.e(TAG, "Exception in ObjectView.save", e); - } finally { - if (fis != null) { - try { - fis.close(); - } catch (Exception e) { - } - } - if (fos != null) { - try { - fos.close(); - } catch (Exception e) { - } - } - if (pfd != null) { - try { - pfd.close(); - } catch (Exception e) { - } - } - } - - if (success) { - Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); - intent.setData(Uri.fromFile(destFile)); - sendBroadcast(intent); + if (resultUri != null) { Toast.makeText(this, R.string.object_saved_message, Toast.LENGTH_SHORT).show(); + Intent intent = new Intent(Intent.ACTION_VIEW, resultUri); + startActivity(intent); } else { Toast.makeText(this, R.string.save_failed_message, Toast.LENGTH_SHORT).show(); } } - private void delete() { + private void deleteObject() { Uri uri = Mtp.Object.getContentUri(mDeviceID, mObjectID); Log.d(TAG, "deleting " + uri); @@ -251,4 +174,12 @@ public class ObjectViewer extends Activity { Toast.makeText(this, R.string.delete_failed_message, Toast.LENGTH_SHORT).show(); } } + + public void onClick(View v) { + if (v == mImportButton) { + importObject(); + } else if (v == mDeleteButton) { + deleteObject(); + } + } } diff --git a/media/tests/CameraBrowser/src/com/android/camerabrowser/StorageBrowser.java b/media/tests/CameraBrowser/src/com/android/camerabrowser/StorageBrowser.java index 63e036e..4da88d6 100644 --- a/media/tests/CameraBrowser/src/com/android/camerabrowser/StorageBrowser.java +++ b/media/tests/CameraBrowser/src/com/android/camerabrowser/StorageBrowser.java @@ -37,6 +37,7 @@ public class StorageBrowser extends ListActivity { private ListAdapter mAdapter; private int mDeviceID; + private DeviceDisconnectedReceiver mDisconnectedReceiver; private static final String[] STORAGE_COLUMNS = new String[] { Mtp.Storage._ID, Mtp.Storage.DESCRIPTION }; @@ -44,13 +45,14 @@ public class StorageBrowser extends ListActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + mDeviceID = getIntent().getIntExtra("device", 0); + mDisconnectedReceiver = new DeviceDisconnectedReceiver(this, mDeviceID); } @Override protected void onResume() { super.onResume(); - mDeviceID = getIntent().getIntExtra("device", 0); if (mDeviceID != 0) { Cursor c = getContentResolver().query(Mtp.Storage.getContentUri(mDeviceID), STORAGE_COLUMNS, null, null, null); @@ -67,6 +69,12 @@ public class StorageBrowser extends ListActivity { } @Override + protected void onDestroy() { + unregisterReceiver(mDisconnectedReceiver); + super.onDestroy(); + } + + @Override protected void onListItemClick(ListView l, View v, int position, long id) { Intent intent = new Intent(this, ObjectBrowser.class); intent.putExtra("device", mDeviceID); diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerGetCurrentPositionStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerGetCurrentPositionStateUnitTest.java index 032b469..fd1c2d3 100644 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerGetCurrentPositionStateUnitTest.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerGetCurrentPositionStateUnitTest.java @@ -45,11 +45,11 @@ public class MediaPlayerGetCurrentPositionStateUnitTest extends AndroidTestCase assertTrue(!stateErrors.errorInPausedState); assertTrue(!stateErrors.errorInStoppedState); assertTrue(!stateErrors.errorInPlaybackCompletedState); - assertTrue(!stateErrors.errorInIdleStateAfterReset); // Invalid states. assertTrue(stateErrors.errorInErrorState); - assertTrue(!stateErrors.errorInIdleState); // onError() won't be called + assertTrue(stateErrors.errorInIdleStateAfterReset); + assertTrue(stateErrors.errorInIdleState); } public void invokeMethodUnderTest(MediaPlayer player) { diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerGetDurationStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerGetDurationStateUnitTest.java index 5f7abe5..48fd16c 100644 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerGetDurationStateUnitTest.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerGetDurationStateUnitTest.java @@ -46,10 +46,10 @@ public class MediaPlayerGetDurationStateUnitTest extends AndroidTestCase impleme assertTrue(!stateErrors.errorInPlaybackCompletedState); // Invalid states. - assertTrue(!stateErrors.errorInIdleState); // onError() won't be called assertTrue(stateErrors.errorInInitializedState); assertTrue(stateErrors.errorInErrorState); assertTrue(stateErrors.errorInIdleStateAfterReset); + assertTrue(stateErrors.errorInIdleState); } public void invokeMethodUnderTest(MediaPlayer player) { diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerPauseStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerPauseStateUnitTest.java index 0a18a39..7a96792 100644 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerPauseStateUnitTest.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerPauseStateUnitTest.java @@ -29,9 +29,9 @@ public class MediaPlayerPauseStateUnitTest extends AndroidTestCase implements Me /** * 1. It is valid to call pause() in the following states: - * {Started, Paused}. + * {Started, Paused, PlaybackCompleted}. * 2. It is invalid to call pause() in the following states: - * {Idle, Initialized, Prepared, Stopped, PlaybackCompleted, Error} + * {Idle, Initialized, Prepared, Stopped, Error} * * @param stateErrors the MediaPlayerStateErrors to check against. */ @@ -40,12 +40,12 @@ public class MediaPlayerPauseStateUnitTest extends AndroidTestCase implements Me assertTrue(!stateErrors.errorInStartedState); assertTrue(!stateErrors.errorInStartedStateAfterPause); assertTrue(!stateErrors.errorInPausedState); + assertTrue(!stateErrors.errorInPlaybackCompletedState); // Invalid states. assertTrue(stateErrors.errorInPreparedState); assertTrue(stateErrors.errorInPreparedStateAfterStop); - assertTrue(stateErrors.errorInPlaybackCompletedState); - assertTrue(!stateErrors.errorInIdleState); // noError() won't be called + assertTrue(stateErrors.errorInIdleState); assertTrue(stateErrors.errorInIdleStateAfterReset); assertTrue(stateErrors.errorInInitializedState); assertTrue(stateErrors.errorInStoppedState); diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerSeekToStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerSeekToStateUnitTest.java index 46bba9b..991fe9c 100644 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerSeekToStateUnitTest.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerSeekToStateUnitTest.java @@ -39,17 +39,17 @@ public class MediaPlayerSeekToStateUnitTest extends AndroidTestCase implements M // Valid states. assertTrue(!stateErrors.errorInPreparedState); assertTrue(!stateErrors.errorInPreparedStateAfterStop); - assertTrue(!stateErrors.errorInStartedState); assertTrue(!stateErrors.errorInStartedStateAfterPause); assertTrue(!stateErrors.errorInPausedState); assertTrue(!stateErrors.errorInPlaybackCompletedState); // Invalid states. - assertTrue(!stateErrors.errorInIdleState); // onError() won't be called + assertTrue(stateErrors.errorInIdleState); assertTrue(stateErrors.errorInIdleStateAfterReset); assertTrue(stateErrors.errorInInitializedState); assertTrue(stateErrors.errorInStoppedState); assertTrue(stateErrors.errorInErrorState); + assertTrue(!stateErrors.errorInStartedState); } public void invokeMethodUnderTest(MediaPlayer player) { diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerSetAudioStreamTypeStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerSetAudioStreamTypeStateUnitTest.java index 3153792..b984514 100644 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerSetAudioStreamTypeStateUnitTest.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerSetAudioStreamTypeStateUnitTest.java @@ -58,7 +58,7 @@ public class MediaPlayerSetAudioStreamTypeStateUnitTest extends AndroidTestCase } @LargeTest - public void testSetAudioSystemType() { + public void testSetAudioStreamType() { mTestTemplate.runTestOnMethod(this); } diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerStartStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerStartStateUnitTest.java index 6debbb4..68c8e42 100644 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerStartStateUnitTest.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerStartStateUnitTest.java @@ -45,7 +45,7 @@ public class MediaPlayerStartStateUnitTest extends AndroidTestCase implements Me assertTrue(!stateErrors.errorInPlaybackCompletedState); // Invalid states. - assertTrue(!stateErrors.errorInIdleState); // onError() won't be called + assertTrue(stateErrors.errorInIdleState); assertTrue(stateErrors.errorInErrorState); assertTrue(stateErrors.errorInIdleStateAfterReset); assertTrue(stateErrors.errorInInitializedState); diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerStopStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerStopStateUnitTest.java index 3427f86..ab8519a 100644 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerStopStateUnitTest.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerStopStateUnitTest.java @@ -46,7 +46,7 @@ public class MediaPlayerStopStateUnitTest extends AndroidTestCase implements Med assertTrue(!stateErrors.errorInPausedState); // Invalid states. - assertTrue(!stateErrors.errorInIdleState); // noError() won't be called + assertTrue(stateErrors.errorInIdleState); assertTrue(stateErrors.errorInIdleStateAfterReset); assertTrue(stateErrors.errorInInitializedState); assertTrue(stateErrors.errorInErrorState); diff --git a/media/tests/mtp/Android.mk b/media/tests/mtp/Android.mk deleted file mode 100644 index a9074ed..0000000 --- a/media/tests/mtp/Android.mk +++ /dev/null @@ -1,61 +0,0 @@ -LOCAL_PATH:= $(call my-dir) - -ifneq ($(TARGET_SIMULATOR),true) - -include $(CLEAR_VARS) - -LOCAL_SRC_FILES := \ - mtp.cpp \ - MtpFile.cpp \ - -LOCAL_C_INCLUDES += \ - frameworks/base/media/mtp \ - -LOCAL_CFLAGS := -DMTP_HOST - -LOCAL_MODULE := mtp - -LOCAL_STATIC_LIBRARIES := libmtp libusbhost libutils libcutils - -include $(BUILD_EXECUTABLE) - -endif - -ifeq ($(HOST_OS),linux) - -include $(CLEAR_VARS) - -LOCAL_SRC_FILES := \ - mtp.cpp \ - MtpFile.cpp \ - ../../../libs/utils/RefBase.cpp \ - ../../../libs/utils/SharedBuffer.cpp \ - ../../../libs/utils/Threads.cpp \ - ../../../libs/utils/VectorImpl.cpp \ - -LOCAL_C_INCLUDES += \ - frameworks/base/media/mtp \ - -LOCAL_CFLAGS := -DMTP_HOST -g -O0 - -have_readline := $(wildcard /usr/include/readline/readline.h) -have_history := $(wildcard /usr/lib/libhistory*) -ifneq ($(strip $(have_readline)),) -LOCAL_CFLAGS += -DHAVE_READLINE=1 -endif - -LOCAL_LDLIBS += -lpthread -ifneq ($(strip $(have_readline)),) -LOCAL_LDLIBS += -lreadline -lncurses -endif -ifneq ($(strip $(have_history)),) -LOCAL_LDLIBS += -lhistory -endif - -LOCAL_MODULE := mtp - -LOCAL_STATIC_LIBRARIES := libmtp libusbhost libcutils - -include $(BUILD_HOST_EXECUTABLE) - -endif diff --git a/media/tests/mtp/MtpFile.cpp b/media/tests/mtp/MtpFile.cpp deleted file mode 100644 index 00d328e..0000000 --- a/media/tests/mtp/MtpFile.cpp +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (C) 2010 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 "MtpClient.h" -#include "MtpDevice.h" -#include "MtpDeviceInfo.h" -#include "MtpObjectInfo.h" -#include "MtpStorage.h" -#include "MtpUtils.h" - -#include "MtpFile.h" - -namespace android { - -MtpClient* MtpFile::sClient = NULL; - -MtpFile::MtpFile(MtpDevice* device) - : mDevice(device), - mStorage(0), - mHandle(0) -{ -} - -MtpFile::MtpFile(MtpDevice* device, MtpStorageID storage) - : mDevice(device), - mStorage(storage), - mHandle(0) -{ -} - -MtpFile::MtpFile(MtpDevice* device, MtpStorageID storage, MtpObjectHandle handle) - : mDevice(device), - mStorage(storage), - mHandle(handle) -{ -} - -MtpFile::MtpFile(MtpFile* file) - : mDevice(file->mDevice), - mStorage(file->mStorage), - mHandle(file->mHandle) -{ -} - -MtpFile::~MtpFile() { -} - -void MtpFile::print() { - if (mHandle) { - - } else if (mStorage) { - printf("%x\n", mStorage); - } else { - int id = mDevice->getID(); - MtpDeviceInfo* info = mDevice->getDeviceInfo(); - if (info) - printf("%d\t%s %s %s\n", id, info->mManufacturer, info->mModel, info->mSerial); - else - printf("%d\t(no device info available)\n", id); - delete info; - } -} - -MtpObjectInfo* MtpFile::getObjectInfo() { - return mDevice->getObjectInfo(mHandle); -} - -void MtpFile::list() { - if (mStorage) { - MtpObjectHandleList* handles = mDevice->getObjectHandles(mStorage, 0, - (mHandle ? mHandle : -1)); - if (handles) { - for (int i = 0; i < handles->size(); i++) { - MtpObjectHandle handle = (*handles)[i]; - MtpObjectInfo* info = mDevice->getObjectInfo(handle); - if (info) { - char modified[100]; - struct tm tm; - - gmtime_r(&info->mDateModified, &tm); - strftime(modified, sizeof(modified), "%a %b %e %H:%M:%S GMT %Y", &tm); - printf("%s Handle: %d Format: %04X Size: %d Modified: %s\n", - info->mName, handle, info->mFormat, info->mCompressedSize, modified); - delete info; - } - } - delete handles; - } - } else { - // list storage units for device - MtpStorageIDList* storageList = mDevice->getStorageIDs(); - for (int i = 0; i < storageList->size(); i++) { - MtpStorageID storageID = (*storageList)[i]; - printf("%x\n", storageID); - } - } -} - -void MtpFile::init(MtpClient* client) { - sClient = client; -} - -MtpFile* MtpFile::parsePath(MtpFile* base, char* path) { - MtpDevice* device = NULL; - MtpStorageID storage = 0; - MtpObjectHandle handle = 0; - - if (path[0] != '/' && base) { - device = base->mDevice; - storage = base->mStorage; - handle = base->mHandle; - } - - // parse an absolute path - if (path[0] == '/') - path++; - char* tok = strtok(path, "/"); - while (tok) { - if (storage) { - // find child of current handle - MtpObjectHandleList* handles = device->getObjectHandles(storage, 0, - (handle ? handle : -1)); - MtpObjectHandle childHandle = 0; - - if (handles) { - for (int i = 0; i < handles->size() && !childHandle; i++) { - MtpObjectHandle handle = (*handles)[i]; - MtpObjectInfo* info = device->getObjectInfo(handle); - if (info && !strcmp(tok, info->mName)) - childHandle = handle; - delete info; - } - delete handles; - } - if (childHandle) - handle = childHandle; - else - return NULL; - } else if (device) { - unsigned int id; - // find storage for the device - if (sscanf(tok, "%x", &id) == 1) { - MtpStorageIDList* storageList = device->getStorageIDs(); - bool found = false; - for (int i = 0; i < storageList->size(); i++) { - if ((*storageList)[i] == id) { - found = true; - break; - } - } - if (found) - storage = id; - else - return NULL; - } - } else { - // find device - unsigned int id; - if (sscanf(tok, "%d", &id) == 1) - device = sClient->getDevice(id); - if (!device) - return NULL; - } - - tok = strtok(NULL, "/"); - } - - if (device) - return new MtpFile(device, storage, handle); - else - return NULL; -} - -} diff --git a/media/tests/mtp/MtpFile.h b/media/tests/mtp/MtpFile.h deleted file mode 100644 index ab8762b..0000000 --- a/media/tests/mtp/MtpFile.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2010 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 _MTP_FILE_H -#define _MTP_FILE_H - -#include "MtpTypes.h" - -namespace android { - -class MtpClient; -class MtpDevice; -class MtpObjectInfo; - -// File-like abstraction for the interactive shell. -// This can be used to represent an MTP device, storage unit or object -// (either file or association). -class MtpFile { -private: - MtpDevice* mDevice; - MtpStorageID mStorage; - MtpObjectHandle mHandle; - static MtpClient* sClient; - -public: - MtpFile(MtpDevice* device); - MtpFile(MtpDevice* device, MtpStorageID storage); - MtpFile(MtpDevice* device, MtpStorageID storage, MtpObjectHandle handle); - MtpFile(MtpFile* file); - virtual ~MtpFile(); - - MtpObjectInfo* getObjectInfo(); - void print(); - void list(); - - inline MtpDevice* getDevice() const { return mDevice; } - - static void init(MtpClient* client); - static MtpFile* parsePath(MtpFile* base, char* path); -}; - -} - -#endif // _MTP_DIRECTORY_H diff --git a/media/tests/mtp/mtp.cpp b/media/tests/mtp/mtp.cpp deleted file mode 100644 index 3202cae..0000000 --- a/media/tests/mtp/mtp.cpp +++ /dev/null @@ -1,370 +0,0 @@ -/* - * Copyright (C) 2010 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 <unistd.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> - -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> - -#if HAVE_READLINE -#include <readline/readline.h> -#include <readline/history.h> -#endif - -#include "MtpClient.h" -#include "MtpDevice.h" -#include "MtpObjectInfo.h" - -#include "MtpFile.h" - -#define PROMPT "mtp> " - -using namespace android; - -static MtpClient* sClient = NULL; - -// current working directory information for interactive shell -static MtpFile* sCurrentDirectory = NULL; - -static MtpFile* parse_path(char* path) { - return MtpFile::parsePath(sCurrentDirectory, path); -} - -class MyClient : public MtpClient { -private: - virtual void deviceAdded(MtpDevice *device) { - } - - virtual void deviceRemoved(MtpDevice *device) { - } - -public: -}; - -static void init() { - sClient = new MyClient; - sClient->start(); - MtpFile::init(sClient); -} - -static int set_cwd(int argc, char* argv[]) { - if (argc != 1) { - fprintf(stderr, "cd should have one argument\n"); - return -1; - } - if (!strcmp(argv[0], "/")) { - delete sCurrentDirectory; - sCurrentDirectory = NULL; - } - else { - MtpFile* file = parse_path(argv[0]); - if (file) { - delete sCurrentDirectory; - sCurrentDirectory = file; - } else { - fprintf(stderr, "could not find %s\n", argv[0]); - return -1; - } - } - return 0; -} - -static void list_devices() { - // TODO - need to make sure the list will not change while iterating - MtpDeviceList& devices = sClient->getDeviceList(); - for (int i = 0; i < devices.size(); i++) { - MtpDevice* device = devices[i]; - MtpFile* file = new MtpFile(device); - file->print(); - delete file; - } -} - -static int list(int argc, char* argv[]) { - if (argc == 0) { - // list cwd - if (sCurrentDirectory) { - sCurrentDirectory->list(); - } else { - list_devices(); - } - } - - for (int i = 0; i < argc; i++) { - char* path = argv[i]; - if (!strcmp(path, "/")) { - list_devices(); - } else { - MtpFile* file = parse_path(path); - if (!file) { - fprintf(stderr, "could not find %s\n", path); - return -1; - } - file->list(); - } - } - - return 0; -} - -static int get_file(int argc, char* argv[]) { - int ret = -1; - int srcFD = -1; - int destFD = -1; - MtpFile* srcFile = NULL; - MtpObjectInfo* info = NULL; - char* dest; - - if (argc < 1) { - fprintf(stderr, "not enough arguments\n"); - return -1; - } else if (argc > 2) { - fprintf(stderr, "too many arguments\n"); - return -1; - } - - // find source object - char* src = argv[0]; - srcFile = parse_path(src); - if (!srcFile) { - fprintf(stderr, "could not find %s\n", src); - return -1; - } - info = srcFile->getObjectInfo(); - if (!info) { - fprintf(stderr, "could not find object info for %s\n", src); - goto fail; - } - if (info->mFormat == MTP_FORMAT_ASSOCIATION) { - fprintf(stderr, "copying directories not implemented yet\n"); - goto fail; - } - - dest = (argc > 1 ? argv[1] : info->mName); - destFD = open(dest, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - if (destFD < 0) { - fprintf(stderr, "could not create %s\n", dest); - goto fail; - } - srcFD = srcFile->getDevice()->readObject(info->mHandle, info->mCompressedSize); - if (srcFD < 0) - goto fail; - - char buffer[65536]; - while (1) { - int count = read(srcFD, buffer, sizeof(buffer)); - if (count <= 0) - break; - write(destFD, buffer, count); - } - // FIXME - error checking and reporting - ret = 0; - -fail: - delete srcFile; - delete info; - if (srcFD >= 0) - close(srcFD); - if (destFD >= 0) - close(destFD); - return ret; -} - -static int put_file(int argc, char* argv[]) { - int ret = -1; - int srcFD = -1; - MtpFile* destFile = NULL; - MtpObjectInfo* srcInfo = NULL; - MtpObjectInfo* destInfo = NULL; - MtpObjectHandle handle; - struct stat statbuf; - const char* lastSlash; - - if (argc < 1) { - fprintf(stderr, "not enough arguments\n"); - return -1; - } else if (argc > 2) { - fprintf(stderr, "too many arguments\n"); - return -1; - } - const char* src = argv[0]; - srcFD = open(src, O_RDONLY); - if (srcFD < 0) { - fprintf(stderr, "could not open %s\n", src); - goto fail; - } - if (argc == 2) { - char* dest = argv[1]; - destFile = parse_path(dest); - if (!destFile) { - fprintf(stderr, "could not find %s\n", dest); - goto fail; - } - } else { - if (!sCurrentDirectory) { - fprintf(stderr, "current working directory not set\n"); - goto fail; - } - destFile = new MtpFile(sCurrentDirectory); - } - - destInfo = destFile->getObjectInfo(); - if (!destInfo) { - fprintf(stderr, "could not find object info destination directory\n"); - goto fail; - } - if (destInfo->mFormat != MTP_FORMAT_ASSOCIATION) { - fprintf(stderr, "destination not a directory\n"); - goto fail; - } - - if (fstat(srcFD, &statbuf)) - goto fail; - - srcInfo = new MtpObjectInfo(0); - srcInfo->mStorageID = destInfo->mStorageID; - srcInfo->mFormat = MTP_FORMAT_EXIF_JPEG; // FIXME - srcInfo->mCompressedSize = statbuf.st_size; - srcInfo->mParent = destInfo->mHandle; - lastSlash = strrchr(src, '/'); - srcInfo->mName = strdup(lastSlash ? lastSlash + 1 : src); - srcInfo->mDateModified = statbuf.st_mtime; - handle = destFile->getDevice()->sendObjectInfo(srcInfo); - if (handle <= 0) { - printf("sendObjectInfo returned %04X\n", handle); - goto fail; - } - if (destFile->getDevice()->sendObject(srcInfo, srcFD)) - ret = 0; - -fail: - delete destFile; - delete srcInfo; - delete destInfo; - if (srcFD >= 0) - close(srcFD); - printf("returning %d\n", ret); - return ret; -} - -typedef int (* command_func)(int argc, char* argv[]); - -struct command_table_entry { - const char* name; - command_func func; -}; - -const command_table_entry command_list[] = { - { "cd", set_cwd }, - { "ls", list }, - { "get", get_file }, - { "put", put_file }, - { NULL, NULL }, -}; - - -static int do_command(int argc, char* argv[]) { - const command_table_entry* command = command_list; - const char* name = *argv++; - argc--; - - while (command->name) { - if (!strcmp(command->name, name)) - return command->func(argc, argv); - else - command++; - } - fprintf(stderr, "unknown command %s\n", name); - return -1; -} - -static int shell() { - int argc; - int result = 0; -#define MAX_ARGS 100 - char* argv[MAX_ARGS]; - -#if HAVE_READLINE - using_history(); -#endif - - while (1) { -#if HAVE_READLINE - char* line = readline(PROMPT); - if (!line) { - printf("\n"); - exit(0); - } -#else - char buffer[1000]; - printf("%s", PROMPT); - char* line = NULL; - size_t length = 0; - - buffer[0] = 0; - fgets(buffer, sizeof(buffer), stdin); - int count = strlen(buffer); - if (count > 0 && buffer[0] == (char)EOF) { - printf("\n"); - exit(0); - } - if (count > 0 && line[count - 1] == '\n') - line[count - 1] == 0; -#endif - char* tok = strtok(line, " \t\n\r"); - if (!tok) - continue; - if (!strcmp(tok, "quit") || !strcmp(tok, "exit")) { - exit(0); - } -#if HAVE_READLINE - add_history(line); -#endif - argc = 0; - while (tok) { - if (argc + 1 == MAX_ARGS) { - fprintf(stderr, "too many arguments\n"); - result = -1; - goto bottom_of_loop; - } - - argv[argc++] = strdup(tok); - tok = strtok(NULL, " \t\n\r"); - } - - result = do_command(argc, argv); - -bottom_of_loop: - for (int i = 0; i < argc; i++) - free(argv[i]); - free(line); - } - - return result; -} - -int main(int argc, char* argv[]) { - init(); - - if (argc == 1) - return shell(); - else - return do_command(argc - 1, argv + 1); -} diff --git a/media/tests/omxjpegdecoder/StreamSource.cpp b/media/tests/omxjpegdecoder/StreamSource.cpp index 76aa85b..5f44203 100644 --- a/media/tests/omxjpegdecoder/StreamSource.cpp +++ b/media/tests/omxjpegdecoder/StreamSource.cpp @@ -35,7 +35,7 @@ status_t StreamSource::initCheck() const { return mStream != NULL ? OK : NO_INIT; } -ssize_t StreamSource::readAt(off_t offset, void *data, size_t size) { +ssize_t StreamSource::readAt(off64_t offset, void *data, size_t size) { Mutex::Autolock autoLock(mLock); mStream->rewind(); @@ -45,7 +45,7 @@ ssize_t StreamSource::readAt(off_t offset, void *data, size_t size) { return result; } -status_t StreamSource::getSize(off_t *size) { +status_t StreamSource::getSize(off64_t *size) { *size = mSize; return OK; } diff --git a/media/tests/omxjpegdecoder/StreamSource.h b/media/tests/omxjpegdecoder/StreamSource.h index c1ed5bf..6c34cbd 100644 --- a/media/tests/omxjpegdecoder/StreamSource.h +++ b/media/tests/omxjpegdecoder/StreamSource.h @@ -32,8 +32,8 @@ public: // Pass the ownership of SkStream to StreamSource. StreamSource(SkStream *SkStream); virtual status_t initCheck() const; - virtual ssize_t readAt(off_t offset, void *data, size_t size); - virtual status_t getSize(off_t *size); + virtual ssize_t readAt(off64_t offset, void *data, size_t size); + virtual status_t getSize(off64_t *size); protected: virtual ~StreamSource(); |