summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
Diffstat (limited to 'media')
-rw-r--r--media/java/android/media/AudioManager.java7
-rw-r--r--media/java/android/media/MtpClient.java10
-rw-r--r--media/java/android/media/MtpCursor.java1
-rw-r--r--media/jni/android_media_MtpClient.cpp64
-rw-r--r--media/jni/soundpool/SoundPool.h1
-rw-r--r--media/libmedia/AudioEffect.cpp55
-rw-r--r--media/libmedia/AudioRecord.cpp14
-rw-r--r--media/libmedia/AudioTrack.cpp16
-rw-r--r--media/libmediaplayerservice/Android.mk1
-rw-r--r--media/libmediaplayerservice/StagefrightRecorder.cpp8
-rw-r--r--media/libstagefright/AMRExtractor.cpp6
-rw-r--r--media/libstagefright/AMRWriter.cpp39
-rw-r--r--media/libstagefright/Android.mk3
-rw-r--r--media/libstagefright/AwesomePlayer.cpp245
-rw-r--r--media/libstagefright/DataSource.cpp4
-rw-r--r--media/libstagefright/FileSource.cpp40
-rw-r--r--media/libstagefright/HTTPStream.cpp21
-rw-r--r--media/libstagefright/JPEGSource.cpp2
-rw-r--r--media/libstagefright/MP3Extractor.cpp30
-rw-r--r--media/libstagefright/MPEG2TSWriter.cpp2
-rw-r--r--media/libstagefright/MPEG4Extractor.cpp56
-rw-r--r--media/libstagefright/MPEG4Writer.cpp139
-rw-r--r--media/libstagefright/MetaData.cpp35
-rw-r--r--media/libstagefright/NuCachedSource2.cpp20
-rw-r--r--media/libstagefright/NuHTTPDataSource.cpp33
-rw-r--r--media/libstagefright/OMXCodec.cpp453
-rw-r--r--media/libstagefright/OggExtractor.cpp32
-rw-r--r--media/libstagefright/SampleIterator.cpp2
-rw-r--r--media/libstagefright/SampleTable.cpp16
-rw-r--r--media/libstagefright/ShoutcastSource.cpp3
-rw-r--r--media/libstagefright/StagefrightMediaScanner.cpp13
-rw-r--r--media/libstagefright/StagefrightMetadataRetriever.cpp29
-rw-r--r--media/libstagefright/ThrottledSource.cpp4
-rw-r--r--media/libstagefright/VBRISeeker.cpp8
-rw-r--r--media/libstagefright/WAVExtractor.cpp12
-rw-r--r--media/libstagefright/XINGSeeker.cpp8
-rw-r--r--media/libstagefright/codecs/avc/dec/AVCDecoder.cpp27
-rw-r--r--media/libstagefright/colorconversion/Android.mk16
-rw-r--r--media/libstagefright/colorconversion/ColorConverter.cpp192
-rw-r--r--media/libstagefright/colorconversion/SoftwareRenderer.cpp147
-rw-r--r--media/libstagefright/httplive/LiveSource.cpp8
-rw-r--r--media/libstagefright/id3/ID3.cpp4
-rw-r--r--media/libstagefright/include/AwesomePlayer.h33
-rw-r--r--media/libstagefright/include/HTTPStream.h7
-rw-r--r--media/libstagefright/include/LiveSource.h6
-rw-r--r--media/libstagefright/include/MP3Extractor.h2
-rw-r--r--media/libstagefright/include/MP3Seeker.h2
-rw-r--r--media/libstagefright/include/MPEG2TSExtractor.h2
-rw-r--r--media/libstagefright/include/MPEG4Extractor.h8
-rw-r--r--media/libstagefright/include/NuCachedSource2.h12
-rw-r--r--media/libstagefright/include/NuHTTPDataSource.h14
-rw-r--r--media/libstagefright/include/SampleIterator.h8
-rw-r--r--media/libstagefright/include/SampleTable.h20
-rw-r--r--media/libstagefright/include/SoftwareRenderer.h13
-rw-r--r--media/libstagefright/include/ThrottledSource.h4
-rw-r--r--media/libstagefright/include/VBRISeeker.h6
-rw-r--r--media/libstagefright/include/WAVExtractor.h2
-rw-r--r--media/libstagefright/include/XINGSeeker.h4
-rw-r--r--media/libstagefright/include/stagefright_string.h54
-rw-r--r--media/libstagefright/matroska/MatroskaExtractor.cpp2
-rw-r--r--media/libstagefright/omx/Android.mk1
-rw-r--r--media/libstagefright/rtsp/ARTPWriter.cpp2
-rw-r--r--media/libstagefright/string.cpp92
-rw-r--r--media/mtp/MtpDataPacket.cpp30
-rw-r--r--media/mtp/MtpDataPacket.h3
-rw-r--r--media/mtp/MtpDevice.cpp157
-rw-r--r--media/mtp/MtpDevice.h9
-rw-r--r--media/tests/CameraBrowser/Android.mk2
-rw-r--r--media/tests/CameraBrowser/AndroidManifest.xml2
-rw-r--r--media/tests/CameraBrowser/res/layout/object_info.xml12
-rw-r--r--media/tests/CameraBrowser/res/menu/object_menu.xml23
-rw-r--r--media/tests/CameraBrowser/res/values/strings.xml6
-rw-r--r--media/tests/CameraBrowser/src/com/android/camerabrowser/DeviceDisconnectedReceiver.java50
-rw-r--r--media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectBrowser.java15
-rw-r--r--media/tests/CameraBrowser/src/com/android/camerabrowser/ObjectViewer.java157
-rw-r--r--media/tests/CameraBrowser/src/com/android/camerabrowser/StorageBrowser.java10
-rw-r--r--media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerGetCurrentPositionStateUnitTest.java4
-rw-r--r--media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerGetDurationStateUnitTest.java2
-rw-r--r--media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerPauseStateUnitTest.java8
-rw-r--r--media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerSeekToStateUnitTest.java4
-rw-r--r--media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerSetAudioStreamTypeStateUnitTest.java2
-rw-r--r--media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerStartStateUnitTest.java2
-rw-r--r--media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerStopStateUnitTest.java2
-rw-r--r--media/tests/mtp/Android.mk61
-rw-r--r--media/tests/mtp/MtpFile.cpp187
-rw-r--r--media/tests/mtp/MtpFile.h57
-rw-r--r--media/tests/mtp/mtp.cpp370
-rw-r--r--media/tests/omxjpegdecoder/StreamSource.cpp4
-rw-r--r--media/tests/omxjpegdecoder/StreamSource.h4
89 files changed, 1150 insertions, 2153 deletions
diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java
index def88ae..9058a7b 100644
--- a/media/java/android/media/AudioManager.java
+++ b/media/java/android/media/AudioManager.java
@@ -984,7 +984,8 @@ public class AudioManager {
* application when it places a phone call, as it will cause signals from the radio layer
* to feed the platform mixer.
*
- * @param mode the requested audio mode (NORMAL, RINGTONE, IN_CALL or IN_COMMUNICATION).
+ * @param mode the requested audio mode ({@link #MODE_NORMAL}, {@link #MODE_RINGTONE},
+ * {@link #MODE_IN_CALL} or {@link #MODE_IN_COMMUNICATION}).
* Informs the HAL about the current audio state so that
* it can route the audio appropriately.
*/
@@ -1000,7 +1001,8 @@ public class AudioManager {
/**
* Returns the current audio mode.
*
- * @return the current audio mode (NORMAL, RINGTONE, IN_CALL or IN_COMMUNICATION).
+ * @return the current audio mode ({@link #MODE_NORMAL}, {@link #MODE_RINGTONE},
+ * {@link #MODE_IN_CALL} or {@link #MODE_IN_COMMUNICATION}).
* Returns the current current audio state from the HAL.
*/
public int getMode() {
@@ -1038,7 +1040,6 @@ public class AudioManager {
*/
public static final int MODE_IN_CALL = AudioSystem.MODE_IN_CALL;
/**
- * @hide
* In communication audio mode. An audio/video chat or VoIP call is established.
*/
public static final int MODE_IN_COMMUNICATION = AudioSystem.MODE_IN_COMMUNICATION;
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/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/Android.mk b/media/libmediaplayerservice/Android.mk
index 3341ff7..a9d537f 100644
--- a/media/libmediaplayerservice/Android.mk
+++ b/media/libmediaplayerservice/Android.mk
@@ -31,7 +31,6 @@ LOCAL_SHARED_LIBRARIES := \
libandroid_runtime \
libstagefright \
libstagefright_omx \
- libstagefright_color_conversion \
libstagefright_foundation \
libsurfaceflinger_client
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..db23836 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) \
@@ -72,6 +71,7 @@ LOCAL_SHARED_LIBRARIES := \
libcrypto
LOCAL_STATIC_LIBRARIES := \
+ libstagefright_color_conversion \
libstagefright_aacdec \
libstagefright_aacenc \
libstagefright_amrnbdec \
@@ -98,7 +98,6 @@ LOCAL_SHARED_LIBRARIES += \
libstagefright_enc_common \
libstagefright_avc_common \
libstagefright_foundation \
- libstagefright_color_conversion
ifeq ($(TARGET_OS)-$(TARGET_SIMULATOR),linux-true)
LOCAL_LDLIBS += -lpthread -ldl
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp
index 538e7bf..fe5162e 100644
--- a/media/libstagefright/AwesomePlayer.cpp
+++ b/media/libstagefright/AwesomePlayer.cpp
@@ -81,16 +81,8 @@ private:
struct AwesomeLocalRenderer : public AwesomeRenderer {
AwesomeLocalRenderer(
- OMX_COLOR_FORMATTYPE colorFormat,
- const sp<Surface> &surface,
- size_t displayWidth, size_t displayHeight,
- size_t decodedWidth, size_t decodedHeight,
- int32_t rotationDegrees)
- : mTarget(NULL) {
- init(colorFormat, surface,
- displayWidth, displayHeight,
- decodedWidth, decodedHeight,
- rotationDegrees);
+ const sp<Surface> &surface, const sp<MetaData> &meta)
+ : mTarget(new SoftwareRenderer(surface, meta)) {
}
virtual void render(MediaBuffer *buffer) {
@@ -111,28 +103,10 @@ protected:
private:
SoftwareRenderer *mTarget;
- void init(
- OMX_COLOR_FORMATTYPE colorFormat,
- const sp<Surface> &surface,
- size_t displayWidth, size_t displayHeight,
- size_t decodedWidth, size_t decodedHeight,
- int32_t rotationDegrees);
-
AwesomeLocalRenderer(const AwesomeLocalRenderer &);
AwesomeLocalRenderer &operator=(const AwesomeLocalRenderer &);;
};
-void AwesomeLocalRenderer::init(
- OMX_COLOR_FORMATTYPE colorFormat,
- const sp<Surface> &surface,
- size_t displayWidth, size_t displayHeight,
- size_t decodedWidth, size_t decodedHeight,
- int32_t rotationDegrees) {
- mTarget = new SoftwareRenderer(
- colorFormat, surface, displayWidth, displayHeight,
- decodedWidth, decodedHeight, rotationDegrees);
-}
-
struct AwesomeNativeWindowRenderer : public AwesomeRenderer {
AwesomeNativeWindowRenderer(
const sp<ANativeWindow> &nativeWindow,
@@ -188,9 +162,7 @@ AwesomePlayer::AwesomePlayer()
mAudioPlayer(NULL),
mFlags(0),
mExtractorFlags(0),
- mLastVideoBuffer(NULL),
mVideoBuffer(NULL),
- mSuspensionState(NULL),
mDecryptHandle(NULL) {
CHECK_EQ(mClient.connect(), OK);
@@ -433,11 +405,6 @@ void AwesomePlayer::reset_l() {
mVideoRenderer.clear();
- if (mLastVideoBuffer) {
- mLastVideoBuffer->release();
- mLastVideoBuffer = NULL;
- }
-
if (mVideoBuffer) {
mVideoBuffer->release();
mVideoBuffer = NULL;
@@ -469,7 +436,6 @@ void AwesomePlayer::reset_l() {
mDurationUs = -1;
mFlags = 0;
mExtractorFlags = 0;
- mVideoWidth = mVideoHeight = -1;
mTimeSourceDeltaUs = 0;
mVideoTimeUs = 0;
@@ -482,9 +448,6 @@ void AwesomePlayer::reset_l() {
mFileSource.clear();
- delete mSuspensionState;
- mSuspensionState = NULL;
-
mBitrate = -1;
}
@@ -499,7 +462,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
@@ -637,11 +600,6 @@ void AwesomePlayer::partial_reset_l() {
mVideoRenderer.clear();
- if (mLastVideoBuffer) {
- mLastVideoBuffer->release();
- mLastVideoBuffer = NULL;
- }
-
if (mVideoBuffer) {
mVideoBuffer->release();
mVideoBuffer = NULL;
@@ -815,9 +773,25 @@ status_t AwesomePlayer::play_l() {
void AwesomePlayer::notifyVideoSize_l() {
sp<MetaData> meta = mVideoSource->getFormat();
- int32_t decodedWidth, decodedHeight;
- CHECK(meta->findInt32(kKeyWidth, &decodedWidth));
- CHECK(meta->findInt32(kKeyHeight, &decodedHeight));
+ int32_t cropLeft, cropTop, cropRight, cropBottom;
+ if (!meta->findRect(
+ kKeyCropRect, &cropLeft, &cropTop, &cropRight, &cropBottom)) {
+ int32_t width, height;
+ CHECK(meta->findInt32(kKeyWidth, &width));
+ CHECK(meta->findInt32(kKeyHeight, &height));
+
+ cropLeft = cropTop = 0;
+ cropRight = width - 1;
+ cropBottom = height - 1;
+
+ LOGV("got dimensions only %d x %d", width, height);
+ } else {
+ LOGV("got crop rect %d, %d, %d, %d",
+ cropLeft, cropTop, cropRight, cropBottom);
+ }
+
+ int32_t usableWidth = cropRight - cropLeft + 1;
+ int32_t usableHeight = cropBottom - cropTop + 1;
int32_t rotationDegrees;
if (!mVideoTrack->getFormat()->findInt32(
@@ -827,10 +801,10 @@ void AwesomePlayer::notifyVideoSize_l() {
if (rotationDegrees == 90 || rotationDegrees == 270) {
notifyListener_l(
- MEDIA_SET_VIDEO_SIZE, decodedHeight, decodedWidth);
+ MEDIA_SET_VIDEO_SIZE, usableHeight, usableWidth);
} else {
notifyListener_l(
- MEDIA_SET_VIDEO_SIZE, decodedWidth, decodedHeight);
+ MEDIA_SET_VIDEO_SIZE, usableWidth, usableHeight);
}
}
@@ -872,12 +846,7 @@ void AwesomePlayer::initRenderer_l() {
// allocate their buffers in local address space. This renderer
// then performs a color conversion and copy to get the data
// into the ANativeBuffer.
- mVideoRenderer = new AwesomeLocalRenderer(
- (OMX_COLOR_FORMATTYPE)format,
- mSurface,
- mVideoWidth, mVideoHeight,
- decodedWidth, decodedHeight,
- rotationDegrees);
+ mVideoRenderer = new AwesomeLocalRenderer(mSurface, meta);
}
}
@@ -1041,20 +1010,6 @@ void AwesomePlayer::seekAudioIfNecessary_l() {
}
}
-status_t AwesomePlayer::getVideoDimensions(
- int32_t *width, int32_t *height) const {
- Mutex::Autolock autoLock(mLock);
-
- if (mVideoWidth < 0 || mVideoHeight < 0) {
- return UNKNOWN_ERROR;
- }
-
- *width = mVideoWidth;
- *height = mVideoHeight;
-
- return OK;
-}
-
void AwesomePlayer::setAudioSource(sp<MediaSource> source) {
CHECK(source != NULL);
@@ -1123,9 +1078,6 @@ status_t AwesomePlayer::initVideoDecoder(uint32_t flags) {
}
}
- CHECK(mVideoTrack->getFormat()->findInt32(kKeyWidth, &mVideoWidth));
- CHECK(mVideoTrack->getFormat()->findInt32(kKeyHeight, &mVideoHeight));
-
status_t err = mVideoSource->start();
if (err != OK) {
@@ -1180,11 +1132,6 @@ void AwesomePlayer::onVideoEvent() {
mVideoEventPending = false;
if (mSeeking) {
- if (mLastVideoBuffer) {
- mLastVideoBuffer->release();
- mLastVideoBuffer = NULL;
- }
-
if (mVideoBuffer) {
mVideoBuffer->release();
mVideoBuffer = NULL;
@@ -1327,11 +1274,7 @@ void AwesomePlayer::onVideoEvent() {
mVideoRenderer->render(mVideoBuffer);
}
- if (mLastVideoBuffer) {
- mLastVideoBuffer->release();
- mLastVideoBuffer = NULL;
- }
- mLastVideoBuffer = mVideoBuffer;
+ mVideoBuffer->release();
mVideoBuffer = NULL;
postVideoEvent_l();
@@ -1745,142 +1688,6 @@ void AwesomePlayer::finishAsyncPrepare_l() {
mPreparedCondition.broadcast();
}
-status_t AwesomePlayer::suspend() {
- LOGV("suspend");
- Mutex::Autolock autoLock(mLock);
-
- if (mSuspensionState != NULL) {
- if (mLastVideoBuffer == NULL) {
- //go into here if video is suspended again
- //after resuming without being played between
- //them
- SuspensionState *state = mSuspensionState;
- mSuspensionState = NULL;
- reset_l();
- mSuspensionState = state;
- return OK;
- }
-
- delete mSuspensionState;
- mSuspensionState = NULL;
- }
-
- if (mFlags & PREPARING) {
- mFlags |= PREPARE_CANCELLED;
- if (mConnectingDataSource != NULL) {
- LOGI("interrupting the connection process");
- mConnectingDataSource->disconnect();
- }
- }
-
- while (mFlags & PREPARING) {
- mPreparedCondition.wait(mLock);
- }
-
- SuspensionState *state = new SuspensionState;
- state->mUri = mUri;
- state->mUriHeaders = mUriHeaders;
- state->mFileSource = mFileSource;
-
- state->mFlags = mFlags & (PLAYING | AUTO_LOOPING | LOOPING | AT_EOS);
- getPosition(&state->mPositionUs);
-
- if (mLastVideoBuffer) {
- size_t size = mLastVideoBuffer->range_length();
-
- if (size) {
- int32_t unreadable;
- if (!mLastVideoBuffer->meta_data()->findInt32(
- kKeyIsUnreadable, &unreadable)
- || unreadable == 0) {
- state->mLastVideoFrameSize = size;
- state->mLastVideoFrame = malloc(size);
- memcpy(state->mLastVideoFrame,
- (const uint8_t *)mLastVideoBuffer->data()
- + mLastVideoBuffer->range_offset(),
- size);
-
- state->mVideoWidth = mVideoWidth;
- state->mVideoHeight = mVideoHeight;
-
- sp<MetaData> meta = mVideoSource->getFormat();
- CHECK(meta->findInt32(kKeyColorFormat, &state->mColorFormat));
- CHECK(meta->findInt32(kKeyWidth, &state->mDecodedWidth));
- CHECK(meta->findInt32(kKeyHeight, &state->mDecodedHeight));
- } else {
- LOGV("Unable to save last video frame, we have no access to "
- "the decoded video data.");
- }
- }
- }
-
- reset_l();
-
- mSuspensionState = state;
-
- return OK;
-}
-
-status_t AwesomePlayer::resume() {
- LOGV("resume");
- Mutex::Autolock autoLock(mLock);
-
- if (mSuspensionState == NULL) {
- return INVALID_OPERATION;
- }
-
- SuspensionState *state = mSuspensionState;
- mSuspensionState = NULL;
-
- status_t err;
- if (state->mFileSource != NULL) {
- err = setDataSource_l(state->mFileSource);
-
- if (err == OK) {
- mFileSource = state->mFileSource;
- }
- } else {
- err = setDataSource_l(state->mUri, &state->mUriHeaders);
- }
-
- if (err != OK) {
- delete state;
- state = NULL;
-
- return err;
- }
-
- seekTo_l(state->mPositionUs);
-
- mFlags = state->mFlags & (AUTO_LOOPING | LOOPING | AT_EOS);
-
- if (state->mLastVideoFrame && mSurface != NULL) {
- mVideoRenderer =
- new AwesomeLocalRenderer(
- (OMX_COLOR_FORMATTYPE)state->mColorFormat,
- mSurface,
- state->mVideoWidth,
- state->mVideoHeight,
- state->mDecodedWidth,
- state->mDecodedHeight,
- 0);
-
- mVideoRendererIsPreview = true;
-
- ((AwesomeLocalRenderer *)mVideoRenderer.get())->render(
- state->mLastVideoFrame, state->mLastVideoFrameSize);
- }
-
- if (state->mFlags & PLAYING) {
- play_l();
- }
-
- mSuspensionState = state;
- state = NULL;
-
- return OK;
-}
-
uint32_t AwesomePlayer::flags() const {
return mExtractorFlags;
}
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/MetaData.cpp b/media/libstagefright/MetaData.cpp
index 63b476e..884f3b4 100644
--- a/media/libstagefright/MetaData.cpp
+++ b/media/libstagefright/MetaData.cpp
@@ -70,6 +70,19 @@ bool MetaData::setPointer(uint32_t key, void *value) {
return setData(key, TYPE_POINTER, &value, sizeof(value));
}
+bool MetaData::setRect(
+ uint32_t key,
+ int32_t left, int32_t top,
+ int32_t right, int32_t bottom) {
+ Rect r;
+ r.mLeft = left;
+ r.mTop = top;
+ r.mRight = right;
+ r.mBottom = bottom;
+
+ return setData(key, TYPE_RECT, &r, sizeof(r));
+}
+
bool MetaData::findCString(uint32_t key, const char **value) {
uint32_t type;
const void *data;
@@ -143,6 +156,28 @@ bool MetaData::findPointer(uint32_t key, void **value) {
return true;
}
+bool MetaData::findRect(
+ uint32_t key,
+ int32_t *left, int32_t *top,
+ int32_t *right, int32_t *bottom) {
+ uint32_t type;
+ const void *data;
+ size_t size;
+ if (!findData(key, &type, &data, &size) || type != TYPE_RECT) {
+ return false;
+ }
+
+ CHECK_EQ(size, sizeof(Rect));
+
+ const Rect *r = (const Rect *)data;
+ *left = r->mLeft;
+ *top = r->mTop;
+ *right = r->mRight;
+ *bottom = r->mBottom;
+
+ return true;
+}
+
bool MetaData::setData(
uint32_t key, uint32_t type, const void *data, size_t size) {
bool overwrote_existing = true;
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/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp
index 6ca0f4f..3f32f2f 100644
--- a/media/libstagefright/OMXCodec.cpp
+++ b/media/libstagefright/OMXCodec.cpp
@@ -38,11 +38,11 @@
#include <binder/IServiceManager.h>
#include <binder/MemoryDealer.h>
#include <binder/ProcessState.h>
+#include <media/stagefright/foundation/ADebug.h>
#include <media/IMediaPlayerService.h>
#include <media/stagefright/HardwareAPI.h>
#include <media/stagefright/MediaBuffer.h>
#include <media/stagefright/MediaBufferGroup.h>
-#include <media/stagefright/MediaDebug.h>
#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/MediaExtractor.h>
#include <media/stagefright/MetaData.h>
@@ -526,7 +526,7 @@ status_t OMXCodec::configureCodec(const sp<MetaData> &meta, uint32_t flags) {
size_t size;
if (meta->findData(kKeyESDS, &type, &data, &size)) {
ESDS esds((const char *)data, size);
- CHECK_EQ(esds.InitCheck(), OK);
+ CHECK_EQ(esds.InitCheck(), (status_t)OK);
const void *codec_specific_data;
size_t codec_specific_data_size;
@@ -541,7 +541,7 @@ status_t OMXCodec::configureCodec(const sp<MetaData> &meta, uint32_t flags) {
const uint8_t *ptr = (const uint8_t *)data;
CHECK(size >= 7);
- CHECK_EQ(ptr[0], 1); // configurationVersion == 1
+ CHECK_EQ((unsigned)ptr[0], 1u); // configurationVersion == 1
uint8_t profile = ptr[1];
uint8_t level = ptr[3];
@@ -730,7 +730,7 @@ void OMXCodec::setMinBufferSize(OMX_U32 portIndex, OMX_U32 size) {
status_t err = mOMX->getParameter(
mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
if ((portIndex == kPortIndexInput && (mQuirks & kInputBufferSizesAreBogus))
|| (def.nBufferSize < size)) {
@@ -739,11 +739,11 @@ void OMXCodec::setMinBufferSize(OMX_U32 portIndex, OMX_U32 size) {
err = mOMX->setParameter(
mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
err = mOMX->getParameter(
mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
// Make sure the setting actually stuck.
if (portIndex == kPortIndexInput
@@ -923,7 +923,7 @@ void OMXCodec::setVideoInputFormat(
}
OMX_COLOR_FORMATTYPE colorFormat;
- CHECK_EQ(OK, findTargetColorFormat(meta, &colorFormat));
+ CHECK_EQ((status_t)OK, findTargetColorFormat(meta, &colorFormat));
status_t err;
OMX_PARAM_PORTDEFINITIONTYPE def;
@@ -932,19 +932,19 @@ void OMXCodec::setVideoInputFormat(
//////////////////////// Input port /////////////////////////
CHECK_EQ(setVideoPortFormatType(
kPortIndexInput, OMX_VIDEO_CodingUnused,
- colorFormat), OK);
+ colorFormat), (status_t)OK);
InitOMXParams(&def);
def.nPortIndex = kPortIndexInput;
err = mOMX->getParameter(
mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
def.nBufferSize = getFrameSize(colorFormat,
stride > 0? stride: -stride, sliceHeight);
- CHECK_EQ(def.eDomain, OMX_PortDomainVideo);
+ CHECK_EQ((int)def.eDomain, (int)OMX_PortDomainVideo);
video_def->nFrameWidth = width;
video_def->nFrameHeight = height;
@@ -956,20 +956,20 @@ void OMXCodec::setVideoInputFormat(
err = mOMX->setParameter(
mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
//////////////////////// Output port /////////////////////////
CHECK_EQ(setVideoPortFormatType(
kPortIndexOutput, compressionFormat, OMX_COLOR_FormatUnused),
- OK);
+ (status_t)OK);
InitOMXParams(&def);
def.nPortIndex = kPortIndexOutput;
err = mOMX->getParameter(
mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
- CHECK_EQ(err, OK);
- CHECK_EQ(def.eDomain, OMX_PortDomainVideo);
+ CHECK_EQ(err, (status_t)OK);
+ CHECK_EQ((int)def.eDomain, (int)OMX_PortDomainVideo);
video_def->nFrameWidth = width;
video_def->nFrameHeight = height;
@@ -984,23 +984,23 @@ void OMXCodec::setVideoInputFormat(
err = mOMX->setParameter(
mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
/////////////////// Codec-specific ////////////////////////
switch (compressionFormat) {
case OMX_VIDEO_CodingMPEG4:
{
- CHECK_EQ(setupMPEG4EncoderParameters(meta), OK);
+ CHECK_EQ(setupMPEG4EncoderParameters(meta), (status_t)OK);
break;
}
case OMX_VIDEO_CodingH263:
- CHECK_EQ(setupH263EncoderParameters(meta), OK);
+ CHECK_EQ(setupH263EncoderParameters(meta), (status_t)OK);
break;
case OMX_VIDEO_CodingAVC:
{
- CHECK_EQ(setupAVCEncoderParameters(meta), OK);
+ CHECK_EQ(setupAVCEncoderParameters(meta), (status_t)OK);
break;
}
@@ -1059,7 +1059,7 @@ status_t OMXCodec::setupBitRate(int32_t bitRate) {
status_t err = mOMX->getParameter(
mNode, OMX_IndexParamVideoBitrate,
&bitrateType, sizeof(bitrateType));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
bitrateType.eControlRate = OMX_Video_ControlRateVariable;
bitrateType.nTargetBitrate = bitRate;
@@ -1067,7 +1067,7 @@ status_t OMXCodec::setupBitRate(int32_t bitRate) {
err = mOMX->setParameter(
mNode, OMX_IndexParamVideoBitrate,
&bitrateType, sizeof(bitrateType));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
return OK;
}
@@ -1132,7 +1132,7 @@ status_t OMXCodec::setupH263EncoderParameters(const sp<MetaData>& meta) {
status_t err = mOMX->getParameter(
mNode, OMX_IndexParamVideoH263, &h263type, sizeof(h263type));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
h263type.nAllowedPictureTypes =
OMX_VIDEO_PictureTypeI | OMX_VIDEO_PictureTypeP;
@@ -1159,10 +1159,10 @@ status_t OMXCodec::setupH263EncoderParameters(const sp<MetaData>& meta) {
err = mOMX->setParameter(
mNode, OMX_IndexParamVideoH263, &h263type, sizeof(h263type));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
- CHECK_EQ(setupBitRate(bitRate), OK);
- CHECK_EQ(setupErrorCorrectionParameters(), OK);
+ CHECK_EQ(setupBitRate(bitRate), (status_t)OK);
+ CHECK_EQ(setupErrorCorrectionParameters(), (status_t)OK);
return OK;
}
@@ -1179,7 +1179,7 @@ status_t OMXCodec::setupMPEG4EncoderParameters(const sp<MetaData>& meta) {
status_t err = mOMX->getParameter(
mNode, OMX_IndexParamVideoMpeg4, &mpeg4type, sizeof(mpeg4type));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
mpeg4type.nSliceHeaderSpacing = 0;
mpeg4type.bSVH = OMX_FALSE;
@@ -1211,10 +1211,10 @@ status_t OMXCodec::setupMPEG4EncoderParameters(const sp<MetaData>& meta) {
err = mOMX->setParameter(
mNode, OMX_IndexParamVideoMpeg4, &mpeg4type, sizeof(mpeg4type));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
- CHECK_EQ(setupBitRate(bitRate), OK);
- CHECK_EQ(setupErrorCorrectionParameters(), OK);
+ CHECK_EQ(setupBitRate(bitRate), (status_t)OK);
+ CHECK_EQ(setupErrorCorrectionParameters(), (status_t)OK);
return OK;
}
@@ -1232,7 +1232,7 @@ status_t OMXCodec::setupAVCEncoderParameters(const sp<MetaData>& meta) {
status_t err = mOMX->getParameter(
mNode, OMX_IndexParamVideoAvc, &h264type, sizeof(h264type));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
h264type.nAllowedPictureTypes =
OMX_VIDEO_PictureTypeI | OMX_VIDEO_PictureTypeP;
@@ -1284,9 +1284,9 @@ status_t OMXCodec::setupAVCEncoderParameters(const sp<MetaData>& meta) {
err = mOMX->setParameter(
mNode, OMX_IndexParamVideoAvc, &h264type, sizeof(h264type));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
- CHECK_EQ(setupBitRate(bitRate), OK);
+ CHECK_EQ(setupBitRate(bitRate), (status_t)OK);
return OK;
}
@@ -1324,8 +1324,8 @@ status_t OMXCodec::setVideoOutputFormat(
status_t err = mOMX->getParameter(
mNode, OMX_IndexParamVideoPortFormat,
&format, sizeof(format));
- CHECK_EQ(err, OK);
- CHECK_EQ(format.eCompressionFormat, OMX_VIDEO_CodingUnused);
+ CHECK_EQ(err, (status_t)OK);
+ CHECK_EQ((int)format.eCompressionFormat, (int)OMX_VIDEO_CodingUnused);
static const int OMX_QCOM_COLOR_FormatYVU420SemiPlanar = 0x7FA30C00;
@@ -1353,7 +1353,7 @@ status_t OMXCodec::setVideoOutputFormat(
err = mOMX->getParameter(
mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
#if 1
// XXX Need a (much) better heuristic to compute input buffer sizes.
@@ -1363,7 +1363,7 @@ status_t OMXCodec::setVideoOutputFormat(
}
#endif
- CHECK_EQ(def.eDomain, OMX_PortDomainVideo);
+ CHECK_EQ((int)def.eDomain, (int)OMX_PortDomainVideo);
video_def->nFrameWidth = width;
video_def->nFrameHeight = height;
@@ -1385,8 +1385,8 @@ status_t OMXCodec::setVideoOutputFormat(
err = mOMX->getParameter(
mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
- CHECK_EQ(err, OK);
- CHECK_EQ(def.eDomain, OMX_PortDomainVideo);
+ CHECK_EQ(err, (status_t)OK);
+ CHECK_EQ((int)def.eDomain, (int)OMX_PortDomainVideo);
#if 0
def.nBufferSize =
@@ -1510,7 +1510,7 @@ OMXCodec::~OMXCodec() {
CHECK(mState == LOADED || mState == ERROR);
status_t err = mOMX->freeNode(mNode);
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
mNode = NULL;
setState(DEAD);
@@ -1527,21 +1527,21 @@ OMXCodec::~OMXCodec() {
status_t OMXCodec::init() {
// mLock is held.
- CHECK_EQ(mState, LOADED);
+ CHECK_EQ((int)mState, (int)LOADED);
status_t err;
if (!(mQuirks & kRequiresLoadedToIdleAfterAllocation)) {
err = mOMX->sendCommand(mNode, OMX_CommandStateSet, OMX_StateIdle);
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
setState(LOADED_TO_IDLE);
}
err = allocateBuffers();
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
if (mQuirks & kRequiresLoadedToIdleAfterAllocation) {
err = mOMX->sendCommand(mNode, OMX_CommandStateSet, OMX_StateIdle);
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
setState(LOADED_TO_IDLE);
}
@@ -1896,10 +1896,10 @@ void OMXCodec::on_message(const omx_message &msg) {
CODEC_LOGV("Port is disabled, freeing buffer %p", buffer);
status_t err = freeBuffer(kPortIndexInput, i);
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
} else if (mState != ERROR
&& mPortStatus[kPortIndexInput] != SHUTTING_DOWN) {
- CHECK_EQ(mPortStatus[kPortIndexInput], ENABLED);
+ CHECK_EQ((int)mPortStatus[kPortIndexInput], (int)ENABLED);
drainInputBuffer(&buffers->editItemAt(i));
}
break;
@@ -1937,7 +1937,7 @@ void OMXCodec::on_message(const omx_message &msg) {
CODEC_LOGV("Port is disabled, freeing buffer %p", buffer);
status_t err = freeBuffer(kPortIndexOutput, i);
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
#if 0
} else if (mPortStatus[kPortIndexOutput] == ENABLED
@@ -1947,7 +1947,7 @@ void OMXCodec::on_message(const omx_message &msg) {
mBufferFilled.signal();
#endif
} else if (mPortStatus[kPortIndexOutput] != SHUTTING_DOWN) {
- CHECK_EQ(mPortStatus[kPortIndexOutput], ENABLED);
+ CHECK_EQ((int)mPortStatus[kPortIndexOutput], (int)ENABLED);
if (info->mMediaBuffer == NULL) {
CHECK(mOMXLivesLocally);
@@ -2045,84 +2045,6 @@ void OMXCodec::on_message(const omx_message &msg) {
}
}
-void OMXCodec::onEvent(OMX_EVENTTYPE event, OMX_U32 data1, OMX_U32 data2) {
- switch (event) {
- case OMX_EventCmdComplete:
- {
- onCmdComplete((OMX_COMMANDTYPE)data1, data2);
- break;
- }
-
- case OMX_EventError:
- {
- CODEC_LOGE("ERROR(0x%08lx, %ld)", data1, data2);
-
- setState(ERROR);
- break;
- }
-
- case OMX_EventPortSettingsChanged:
- {
- CODEC_LOGV("OMX_EventPortSettingsChanged(port=%ld, data2=0x%08lx)",
- data1, data2);
-
- if (data2 == 0 || data2 == OMX_IndexParamPortDefinition) {
- onPortSettingsChanged(data1);
- } else if (data1 == kPortIndexOutput
- && data2 == OMX_IndexConfigCommonOutputCrop) {
-
- OMX_CONFIG_RECTTYPE rect;
- rect.nPortIndex = kPortIndexOutput;
- InitOMXParams(&rect);
-
- status_t err =
- mOMX->getConfig(
- mNode, OMX_IndexConfigCommonOutputCrop,
- &rect, sizeof(rect));
-
- if (err == OK) {
- CODEC_LOGV(
- "output crop (%ld, %ld, %ld, %ld)",
- rect.nLeft, rect.nTop, rect.nWidth, rect.nHeight);
-
- if (mNativeWindow != NULL) {
- android_native_rect_t crop;
- crop.left = rect.nLeft;
- crop.top = rect.nTop;
- crop.right = crop.left + rect.nWidth - 1;
- crop.bottom = crop.top + rect.nHeight - 1;
-
- CHECK_EQ(0, native_window_set_crop(
- mNativeWindow.get(), &crop));
- }
- } else {
- CODEC_LOGE("getConfig(OMX_IndexConfigCommonOutputCrop) "
- "returned error 0x%08x", err);
- }
- }
- break;
- }
-
-#if 0
- case OMX_EventBufferFlag:
- {
- CODEC_LOGV("EVENT_BUFFER_FLAG(%ld)", data1);
-
- if (data1 == kPortIndexOutput) {
- mNoMoreOutputData = true;
- }
- break;
- }
-#endif
-
- default:
- {
- CODEC_LOGV("EVENT(%d, %ld, %ld)", event, data1, data2);
- break;
- }
- }
-}
-
// Has the format changed in any way that the client would have to be aware of?
static bool formatHasNotablyChanged(
const sp<MetaData> &from, const sp<MetaData> &to) {
@@ -2167,6 +2089,21 @@ static bool formatHasNotablyChanged(
if (height_from != height_to) {
return true;
}
+
+ int32_t left_from, top_from, right_from, bottom_from;
+ CHECK(from->findRect(
+ kKeyCropRect,
+ &left_from, &top_from, &right_from, &bottom_from));
+
+ int32_t left_to, top_to, right_to, bottom_to;
+ CHECK(to->findRect(
+ kKeyCropRect,
+ &left_to, &top_to, &right_to, &bottom_to));
+
+ if (left_to != left_from || top_to != top_from
+ || right_to != right_from || bottom_to != bottom_from) {
+ return true;
+ }
} else if (!strcasecmp(mime_from, MEDIA_MIMETYPE_AUDIO_RAW)) {
int32_t numChannels_from, numChannels_to;
CHECK(from->findInt32(kKeyChannelCount, &numChannels_from));
@@ -2188,6 +2125,78 @@ static bool formatHasNotablyChanged(
return false;
}
+void OMXCodec::onEvent(OMX_EVENTTYPE event, OMX_U32 data1, OMX_U32 data2) {
+ switch (event) {
+ case OMX_EventCmdComplete:
+ {
+ onCmdComplete((OMX_COMMANDTYPE)data1, data2);
+ break;
+ }
+
+ case OMX_EventError:
+ {
+ CODEC_LOGE("ERROR(0x%08lx, %ld)", data1, data2);
+
+ setState(ERROR);
+ break;
+ }
+
+ case OMX_EventPortSettingsChanged:
+ {
+ CODEC_LOGV("OMX_EventPortSettingsChanged(port=%ld, data2=0x%08lx)",
+ data1, data2);
+
+ if (data2 == 0 || data2 == OMX_IndexParamPortDefinition) {
+ onPortSettingsChanged(data1);
+ } else if (data1 == kPortIndexOutput
+ && data2 == OMX_IndexConfigCommonOutputCrop) {
+
+ sp<MetaData> oldOutputFormat = mOutputFormat;
+ initOutputFormat(mSource->getFormat());
+
+ if (formatHasNotablyChanged(oldOutputFormat, mOutputFormat)) {
+ mOutputPortSettingsHaveChanged = true;
+
+ if (mNativeWindow != NULL) {
+ int32_t left, top, right, bottom;
+ CHECK(mOutputFormat->findRect(
+ kKeyCropRect,
+ &left, &top, &right, &bottom));
+
+ android_native_rect_t crop;
+ crop.left = left;
+ crop.top = top;
+ crop.right = right;
+ crop.bottom = bottom;
+
+ CHECK_EQ(0, native_window_set_crop(
+ mNativeWindow.get(), &crop));
+ }
+ }
+ }
+ break;
+ }
+
+#if 0
+ case OMX_EventBufferFlag:
+ {
+ CODEC_LOGV("EVENT_BUFFER_FLAG(%ld)", data1);
+
+ if (data1 == kPortIndexOutput) {
+ mNoMoreOutputData = true;
+ }
+ break;
+ }
+#endif
+
+ default:
+ {
+ CODEC_LOGV("EVENT(%d, %ld, %ld)", event, data1, data2);
+ break;
+ }
+ }
+}
+
void OMXCodec::onCmdComplete(OMX_COMMANDTYPE cmd, OMX_U32 data) {
switch (cmd) {
case OMX_CommandStateSet:
@@ -2202,13 +2211,13 @@ void OMXCodec::onCmdComplete(OMX_COMMANDTYPE cmd, OMX_U32 data) {
CODEC_LOGV("PORT_DISABLED(%ld)", portIndex);
CHECK(mState == EXECUTING || mState == RECONFIGURING);
- CHECK_EQ(mPortStatus[portIndex], DISABLING);
- CHECK_EQ(mPortBuffers[portIndex].size(), 0);
+ CHECK_EQ((int)mPortStatus[portIndex], (int)DISABLING);
+ CHECK_EQ(mPortBuffers[portIndex].size(), 0u);
mPortStatus[portIndex] = DISABLED;
if (mState == RECONFIGURING) {
- CHECK_EQ(portIndex, kPortIndexOutput);
+ CHECK_EQ(portIndex, (OMX_U32)kPortIndexOutput);
sp<MetaData> oldOutputFormat = mOutputFormat;
initOutputFormat(mSource->getFormat());
@@ -2222,7 +2231,7 @@ void OMXCodec::onCmdComplete(OMX_COMMANDTYPE cmd, OMX_U32 data) {
enablePortAsync(portIndex);
status_t err = allocateBuffersOnPort(portIndex);
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
}
break;
}
@@ -2233,12 +2242,12 @@ void OMXCodec::onCmdComplete(OMX_COMMANDTYPE cmd, OMX_U32 data) {
CODEC_LOGV("PORT_ENABLED(%ld)", portIndex);
CHECK(mState == EXECUTING || mState == RECONFIGURING);
- CHECK_EQ(mPortStatus[portIndex], ENABLING);
+ CHECK_EQ((int)mPortStatus[portIndex], (int)ENABLING);
mPortStatus[portIndex] = ENABLED;
if (mState == RECONFIGURING) {
- CHECK_EQ(portIndex, kPortIndexOutput);
+ CHECK_EQ(portIndex, (OMX_U32)kPortIndexOutput);
setState(EXECUTING);
@@ -2253,14 +2262,14 @@ void OMXCodec::onCmdComplete(OMX_COMMANDTYPE cmd, OMX_U32 data) {
CODEC_LOGV("FLUSH_DONE(%ld)", portIndex);
- CHECK_EQ(mPortStatus[portIndex], SHUTTING_DOWN);
+ CHECK_EQ((int)mPortStatus[portIndex], (int)SHUTTING_DOWN);
mPortStatus[portIndex] = ENABLED;
CHECK_EQ(countBuffersWeOwn(mPortBuffers[portIndex]),
mPortBuffers[portIndex].size());
if (mState == RECONFIGURING) {
- CHECK_EQ(portIndex, kPortIndexOutput);
+ CHECK_EQ(portIndex, (OMX_U32)kPortIndexOutput);
disablePortAsync(portIndex);
} else if (mState == EXECUTING_TO_IDLE) {
@@ -2274,7 +2283,7 @@ void OMXCodec::onCmdComplete(OMX_COMMANDTYPE cmd, OMX_U32 data) {
status_t err =
mOMX->sendCommand(mNode, OMX_CommandStateSet, OMX_StateIdle);
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
}
} else {
// We're flushing both ports in preparation for seeking.
@@ -2314,11 +2323,11 @@ void OMXCodec::onStateChange(OMX_STATETYPE newState) {
status_t err = mOMX->sendCommand(
mNode, OMX_CommandStateSet, OMX_StateExecuting);
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
setState(IDLE_TO_EXECUTING);
} else {
- CHECK_EQ(mState, EXECUTING_TO_IDLE);
+ CHECK_EQ((int)mState, (int)EXECUTING_TO_IDLE);
CHECK_EQ(
countBuffersWeOwn(mPortBuffers[kPortIndexInput]),
@@ -2331,13 +2340,13 @@ void OMXCodec::onStateChange(OMX_STATETYPE newState) {
status_t err = mOMX->sendCommand(
mNode, OMX_CommandStateSet, OMX_StateLoaded);
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
err = freeBuffersOnPort(kPortIndexInput);
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
err = freeBuffersOnPort(kPortIndexOutput);
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
mPortStatus[kPortIndexInput] = ENABLED;
mPortStatus[kPortIndexOutput] = ENABLED;
@@ -2349,7 +2358,7 @@ void OMXCodec::onStateChange(OMX_STATETYPE newState) {
case OMX_StateExecuting:
{
- CHECK_EQ(mState, IDLE_TO_EXECUTING);
+ CHECK_EQ((int)mState, (int)IDLE_TO_EXECUTING);
CODEC_LOGV("Now Executing.");
@@ -2365,7 +2374,7 @@ void OMXCodec::onStateChange(OMX_STATETYPE newState) {
case OMX_StateLoaded:
{
- CHECK_EQ(mState, IDLE_TO_LOADED);
+ CHECK_EQ((int)mState, (int)IDLE_TO_LOADED);
CODEC_LOGV("Now Loaded.");
@@ -2412,7 +2421,7 @@ status_t OMXCodec::freeBuffersOnPort(
continue;
}
- CHECK_EQ(info->mOwnedByComponent, false);
+ CHECK_EQ((int)info->mOwnedByComponent, (int)false);
CODEC_LOGV("freeing buffer %p on port %ld", info->mBuffer, portIndex);
@@ -2437,7 +2446,7 @@ status_t OMXCodec::freeBuffer(OMX_U32 portIndex, size_t bufIndex) {
status_t err = mOMX->freeBuffer(mNode, portIndex, info->mBuffer);
if (err == OK && info->mMediaBuffer != NULL) {
- CHECK_EQ(portIndex, kPortIndexOutput);
+ CHECK_EQ(portIndex, (OMX_U32)kPortIndexOutput);
info->mMediaBuffer->setObserver(NULL);
// Make sure nobody but us owns this buffer at this point.
@@ -2463,8 +2472,8 @@ status_t OMXCodec::freeBuffer(OMX_U32 portIndex, size_t bufIndex) {
void OMXCodec::onPortSettingsChanged(OMX_U32 portIndex) {
CODEC_LOGV("PORT_SETTINGS_CHANGED(%ld)", portIndex);
- CHECK_EQ(mState, EXECUTING);
- CHECK_EQ(portIndex, kPortIndexOutput);
+ CHECK_EQ((int)mState, (int)EXECUTING);
+ CHECK_EQ(portIndex, (OMX_U32)kPortIndexOutput);
setState(RECONFIGURING);
if (mQuirks & kNeedsFlushBeforeDisable) {
@@ -2484,7 +2493,7 @@ bool OMXCodec::flushPortAsync(OMX_U32 portIndex) {
portIndex, countBuffersWeOwn(mPortBuffers[portIndex]),
mPortBuffers[portIndex].size());
- CHECK_EQ(mPortStatus[portIndex], ENABLED);
+ CHECK_EQ((int)mPortStatus[portIndex], (int)ENABLED);
mPortStatus[portIndex] = SHUTTING_DOWN;
if ((mQuirks & kRequiresFlushCompleteEmulation)
@@ -2498,7 +2507,7 @@ bool OMXCodec::flushPortAsync(OMX_U32 portIndex) {
status_t err =
mOMX->sendCommand(mNode, OMX_CommandFlush, portIndex);
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
return true;
}
@@ -2506,13 +2515,13 @@ bool OMXCodec::flushPortAsync(OMX_U32 portIndex) {
void OMXCodec::disablePortAsync(OMX_U32 portIndex) {
CHECK(mState == EXECUTING || mState == RECONFIGURING);
- CHECK_EQ(mPortStatus[portIndex], ENABLED);
+ CHECK_EQ((int)mPortStatus[portIndex], (int)ENABLED);
mPortStatus[portIndex] = DISABLING;
CODEC_LOGV("sending OMX_CommandPortDisable(%ld)", portIndex);
status_t err =
mOMX->sendCommand(mNode, OMX_CommandPortDisable, portIndex);
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
freeBuffersOnPort(portIndex, true);
}
@@ -2520,17 +2529,17 @@ void OMXCodec::disablePortAsync(OMX_U32 portIndex) {
void OMXCodec::enablePortAsync(OMX_U32 portIndex) {
CHECK(mState == EXECUTING || mState == RECONFIGURING);
- CHECK_EQ(mPortStatus[portIndex], DISABLED);
+ CHECK_EQ((int)mPortStatus[portIndex], (int)DISABLED);
mPortStatus[portIndex] = ENABLING;
CODEC_LOGV("sending OMX_CommandPortEnable(%ld)", portIndex);
status_t err =
mOMX->sendCommand(mNode, OMX_CommandPortEnable, portIndex);
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
}
void OMXCodec::fillOutputBuffers() {
- CHECK_EQ(mState, EXECUTING);
+ CHECK_EQ((int)mState, (int)EXECUTING);
// This is a workaround for some decoders not properly reporting
// end-of-output-stream. If we own all input buffers and also own
@@ -2566,7 +2575,7 @@ void OMXCodec::drainInputBuffers() {
}
void OMXCodec::drainInputBuffer(BufferInfo *info) {
- CHECK_EQ(info->mOwnedByComponent, false);
+ CHECK_EQ((int)info->mOwnedByComponent, (int)false);
if (mSignalledEOS) {
return;
@@ -2603,7 +2612,7 @@ void OMXCodec::drainInputBuffer(BufferInfo *info) {
mNode, info->mBuffer, 0, size,
OMX_BUFFERFLAG_ENDOFFRAME | OMX_BUFFERFLAG_CODECCONFIG,
0);
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
info->mOwnedByComponent = true;
@@ -2771,7 +2780,7 @@ void OMXCodec::drainInputBuffer(BufferInfo *info) {
}
void OMXCodec::fillOutputBuffer(BufferInfo *info) {
- CHECK_EQ(info->mOwnedByComponent, false);
+ CHECK_EQ((int)info->mOwnedByComponent, (int)false);
if (mNoMoreOutputData) {
CODEC_LOGV("There is no more output data available, not "
@@ -2779,19 +2788,21 @@ void OMXCodec::fillOutputBuffer(BufferInfo *info) {
return;
}
- sp<GraphicBuffer> graphicBuffer = info->mMediaBuffer->graphicBuffer();
- if (graphicBuffer != 0) {
- // When using a native buffer we need to lock the buffer before giving
- // it to OMX.
- CHECK(!info->mOwnedByNativeWindow);
- CODEC_LOGV("Calling lockBuffer on %p", info->mBuffer);
- int err = mNativeWindow->lockBuffer(mNativeWindow.get(),
- graphicBuffer.get());
- if (err != 0) {
- CODEC_LOGE("lockBuffer failed w/ error 0x%08x", err);
+ if (info->mMediaBuffer != NULL) {
+ sp<GraphicBuffer> graphicBuffer = info->mMediaBuffer->graphicBuffer();
+ if (graphicBuffer != 0) {
+ // When using a native buffer we need to lock the buffer before
+ // giving it to OMX.
+ CHECK(!info->mOwnedByNativeWindow);
+ CODEC_LOGV("Calling lockBuffer on %p", info->mBuffer);
+ int err = mNativeWindow->lockBuffer(mNativeWindow.get(),
+ graphicBuffer.get());
+ if (err != 0) {
+ CODEC_LOGE("lockBuffer failed w/ error 0x%08x", err);
- setState(ERROR);
- return;
+ setState(ERROR);
+ return;
+ }
}
}
@@ -2850,10 +2861,10 @@ void OMXCodec::setRawAudioFormat(
def.nPortIndex = portIndex;
status_t err = mOMX->getParameter(
mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
def.format.audio.eEncoding = OMX_AUDIO_CodingPCM;
CHECK_EQ(mOMX->setParameter(mNode, OMX_IndexParamPortDefinition,
- &def, sizeof(def)), OK);
+ &def, sizeof(def)), (status_t)OK);
// pcm param
OMX_AUDIO_PARAM_PCMMODETYPE pcmParams;
@@ -2863,7 +2874,7 @@ void OMXCodec::setRawAudioFormat(
err = mOMX->getParameter(
mNode, OMX_IndexParamAudioPcm, &pcmParams, sizeof(pcmParams));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
pcmParams.nChannels = numChannels;
pcmParams.eNumData = OMX_NumericalDataSigned;
@@ -2884,7 +2895,7 @@ void OMXCodec::setRawAudioFormat(
err = mOMX->setParameter(
mNode, OMX_IndexParamAudioPcm, &pcmParams, sizeof(pcmParams));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
}
static OMX_AUDIO_AMRBANDMODETYPE pickModeFromBitRate(bool isAMRWB, int32_t bps) {
@@ -2941,13 +2952,13 @@ void OMXCodec::setAMRFormat(bool isWAMR, int32_t bitRate) {
status_t err =
mOMX->getParameter(mNode, OMX_IndexParamAudioAmr, &def, sizeof(def));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
def.eAMRFrameFormat = OMX_AUDIO_AMRFrameFormatFSF;
def.eAMRBandMode = pickModeFromBitRate(isWAMR, bitRate);
err = mOMX->setParameter(mNode, OMX_IndexParamAudioAmr, &def, sizeof(def));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
////////////////////////
@@ -2976,33 +2987,33 @@ void OMXCodec::setAACFormat(int32_t numChannels, int32_t sampleRate, int32_t bit
status_t err = OMX_ErrorNone;
while (OMX_ErrorNone == err) {
CHECK_EQ(mOMX->getParameter(mNode, OMX_IndexParamAudioPortFormat,
- &format, sizeof(format)), OK);
+ &format, sizeof(format)), (status_t)OK);
if (format.eEncoding == OMX_AUDIO_CodingAAC) {
break;
}
format.nIndex++;
}
- CHECK_EQ(OK, err);
+ CHECK_EQ((status_t)OK, err);
CHECK_EQ(mOMX->setParameter(mNode, OMX_IndexParamAudioPortFormat,
- &format, sizeof(format)), OK);
+ &format, sizeof(format)), (status_t)OK);
// port definition
OMX_PARAM_PORTDEFINITIONTYPE def;
InitOMXParams(&def);
def.nPortIndex = kPortIndexOutput;
CHECK_EQ(mOMX->getParameter(mNode, OMX_IndexParamPortDefinition,
- &def, sizeof(def)), OK);
+ &def, sizeof(def)), (status_t)OK);
def.format.audio.bFlagErrorConcealment = OMX_TRUE;
def.format.audio.eEncoding = OMX_AUDIO_CodingAAC;
CHECK_EQ(mOMX->setParameter(mNode, OMX_IndexParamPortDefinition,
- &def, sizeof(def)), OK);
+ &def, sizeof(def)), (status_t)OK);
// profile
OMX_AUDIO_PARAM_AACPROFILETYPE profile;
InitOMXParams(&profile);
profile.nPortIndex = kPortIndexOutput;
CHECK_EQ(mOMX->getParameter(mNode, OMX_IndexParamAudioAac,
- &profile, sizeof(profile)), OK);
+ &profile, sizeof(profile)), (status_t)OK);
profile.nChannels = numChannels;
profile.eChannelMode = (numChannels == 1?
OMX_AUDIO_ChannelModeMono: OMX_AUDIO_ChannelModeStereo);
@@ -3015,7 +3026,7 @@ void OMXCodec::setAACFormat(int32_t numChannels, int32_t sampleRate, int32_t bit
profile.eAACProfile = OMX_AUDIO_AACObjectLC;
profile.eAACStreamFormat = OMX_AUDIO_AACStreamFormatMP4FF;
CHECK_EQ(mOMX->setParameter(mNode, OMX_IndexParamAudioAac,
- &profile, sizeof(profile)), OK);
+ &profile, sizeof(profile)), (status_t)OK);
} else {
OMX_AUDIO_PARAM_AACPROFILETYPE profile;
@@ -3024,7 +3035,7 @@ void OMXCodec::setAACFormat(int32_t numChannels, int32_t sampleRate, int32_t bit
status_t err = mOMX->getParameter(
mNode, OMX_IndexParamAudioAac, &profile, sizeof(profile));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
profile.nChannels = numChannels;
profile.nSampleRate = sampleRate;
@@ -3032,7 +3043,7 @@ void OMXCodec::setAACFormat(int32_t numChannels, int32_t sampleRate, int32_t bit
err = mOMX->setParameter(
mNode, OMX_IndexParamAudioAac, &profile, sizeof(profile));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
}
}
@@ -3044,10 +3055,10 @@ void OMXCodec::setImageOutputFormat(
OMX_INDEXTYPE index;
status_t err = mOMX->get_extension_index(
mNode, "OMX.TI.JPEG.decode.Config.OutputColorFormat", &index);
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
err = mOMX->set_config(mNode, index, &format, sizeof(format));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
#endif
OMX_PARAM_PORTDEFINITIONTYPE def;
@@ -3056,13 +3067,13 @@ void OMXCodec::setImageOutputFormat(
status_t err = mOMX->getParameter(
mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
- CHECK_EQ(def.eDomain, OMX_PortDomainImage);
+ CHECK_EQ((int)def.eDomain, (int)OMX_PortDomainImage);
OMX_IMAGE_PORTDEFINITIONTYPE *imageDef = &def.format.image;
- CHECK_EQ(imageDef->eCompressionFormat, OMX_IMAGE_CodingUnused);
+ CHECK_EQ((int)imageDef->eCompressionFormat, (int)OMX_IMAGE_CodingUnused);
imageDef->eColorFormat = format;
imageDef->nFrameWidth = width;
imageDef->nFrameHeight = height;
@@ -3105,7 +3116,7 @@ void OMXCodec::setImageOutputFormat(
err = mOMX->setParameter(
mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
}
void OMXCodec::setJPEGInputFormat(
@@ -3116,12 +3127,12 @@ void OMXCodec::setJPEGInputFormat(
status_t err = mOMX->getParameter(
mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
- CHECK_EQ(def.eDomain, OMX_PortDomainImage);
+ CHECK_EQ((int)def.eDomain, (int)OMX_PortDomainImage);
OMX_IMAGE_PORTDEFINITIONTYPE *imageDef = &def.format.image;
- CHECK_EQ(imageDef->eCompressionFormat, OMX_IMAGE_CodingJPEG);
+ CHECK_EQ((int)imageDef->eCompressionFormat, (int)OMX_IMAGE_CodingJPEG);
imageDef->nFrameWidth = width;
imageDef->nFrameHeight = height;
@@ -3130,7 +3141,7 @@ void OMXCodec::setJPEGInputFormat(
err = mOMX->setParameter(
mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
}
void OMXCodec::addCodecSpecificData(const void *data, size_t size) {
@@ -3231,7 +3242,7 @@ status_t OMXCodec::stop() {
status_t err =
mOMX->sendCommand(mNode, OMX_CommandStateSet, OMX_StateIdle);
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
}
while (mState != LOADED && mState != ERROR) {
@@ -3323,7 +3334,7 @@ status_t OMXCodec::read(
mFilledBuffers.clear();
- CHECK_EQ(mState, EXECUTING);
+ CHECK_EQ((int)mState, (int)EXECUTING);
bool emulateInputFlushCompletion = !flushPortAsync(kPortIndexInput);
bool emulateOutputFlushCompletion = !flushPortAsync(kPortIndexOutput);
@@ -3377,7 +3388,7 @@ void OMXCodec::signalBufferReturned(MediaBuffer *buffer) {
BufferInfo *info = &buffers->editItemAt(i);
if (info->mMediaBuffer == buffer) {
- CHECK_EQ(mPortStatus[kPortIndexOutput], ENABLED);
+ CHECK_EQ((int)mPortStatus[kPortIndexOutput], (int)ENABLED);
if (buffer->graphicBuffer() == 0) {
fillOutputBuffer(info);
} else {
@@ -3629,7 +3640,7 @@ void OMXCodec::dumpPortStatus(OMX_U32 portIndex) {
status_t err = mOMX->getParameter(
mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
printf("%s Port = {\n", portIndex == kPortIndexInput ? "Input" : "Output");
@@ -3695,7 +3706,7 @@ void OMXCodec::dumpPortStatus(OMX_U32 portIndex) {
err = mOMX->getParameter(
mNode, OMX_IndexParamAudioPcm, &params, sizeof(params));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
printf(" nSamplingRate = %ld\n", params.nSamplingRate);
printf(" nChannels = %ld\n", params.nChannels);
@@ -3714,7 +3725,7 @@ void OMXCodec::dumpPortStatus(OMX_U32 portIndex) {
err = mOMX->getParameter(
mNode, OMX_IndexParamAudioAmr, &amr, sizeof(amr));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
printf(" nChannels = %ld\n", amr.nChannels);
printf(" eAMRBandMode = %s\n",
@@ -3764,13 +3775,14 @@ void OMXCodec::initOutputFormat(const sp<MetaData> &inputFormat) {
status_t err = mOMX->getParameter(
mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
switch (def.eDomain) {
case OMX_PortDomainImage:
{
OMX_IMAGE_PORTDEFINITIONTYPE *imageDef = &def.format.image;
- CHECK_EQ(imageDef->eCompressionFormat, OMX_IMAGE_CodingUnused);
+ CHECK_EQ((int)imageDef->eCompressionFormat,
+ (int)OMX_IMAGE_CodingUnused);
mOutputFormat->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_RAW);
mOutputFormat->setInt32(kKeyColorFormat, imageDef->eColorFormat);
@@ -3790,11 +3802,11 @@ void OMXCodec::initOutputFormat(const sp<MetaData> &inputFormat) {
err = mOMX->getParameter(
mNode, OMX_IndexParamAudioPcm, &params, sizeof(params));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
- CHECK_EQ(params.eNumData, OMX_NumericalDataSigned);
- CHECK_EQ(params.nBitPerSample, 16);
- CHECK_EQ(params.ePCMMode, OMX_AUDIO_PCMModeLinear);
+ CHECK_EQ((int)params.eNumData, (int)OMX_NumericalDataSigned);
+ CHECK_EQ(params.nBitPerSample, 16u);
+ CHECK_EQ((int)params.ePCMMode, (int)OMX_AUDIO_PCMModeLinear);
int32_t numChannels, sampleRate;
inputFormat->findInt32(kKeyChannelCount, &numChannels);
@@ -3828,9 +3840,9 @@ void OMXCodec::initOutputFormat(const sp<MetaData> &inputFormat) {
err = mOMX->getParameter(
mNode, OMX_IndexParamAudioAmr, &amr, sizeof(amr));
- CHECK_EQ(err, OK);
+ CHECK_EQ(err, (status_t)OK);
- CHECK_EQ(amr.nChannels, 1);
+ CHECK_EQ(amr.nChannels, 1u);
mOutputFormat->setInt32(kKeyChannelCount, 1);
if (amr.eAMRBandMode >= OMX_AUDIO_AMRBandModeNB0
@@ -3885,6 +3897,35 @@ void OMXCodec::initOutputFormat(const sp<MetaData> &inputFormat) {
mOutputFormat->setInt32(kKeyWidth, video_def->nFrameWidth);
mOutputFormat->setInt32(kKeyHeight, video_def->nFrameHeight);
mOutputFormat->setInt32(kKeyColorFormat, video_def->eColorFormat);
+
+ OMX_CONFIG_RECTTYPE rect;
+ status_t err =
+ mOMX->getConfig(
+ mNode, OMX_IndexConfigCommonOutputCrop,
+ &rect, sizeof(rect));
+
+ if (err == OK) {
+ CHECK_GE(rect.nLeft, 0);
+ CHECK_GE(rect.nTop, 0);
+ CHECK_GE(rect.nWidth, 0u);
+ CHECK_GE(rect.nHeight, 0u);
+ CHECK_LE(rect.nLeft + rect.nWidth - 1, video_def->nFrameWidth);
+ CHECK_LE(rect.nTop + rect.nHeight - 1, video_def->nFrameHeight);
+
+ mOutputFormat->setRect(
+ kKeyCropRect,
+ rect.nLeft,
+ rect.nTop,
+ rect.nLeft + rect.nWidth - 1,
+ rect.nTop + rect.nHeight - 1);
+ } else {
+ mOutputFormat->setRect(
+ kKeyCropRect,
+ 0, 0,
+ video_def->nFrameWidth - 1,
+ video_def->nFrameHeight - 1);
+ }
+
break;
}
@@ -3988,7 +4029,7 @@ status_t QueryCodecs(
caps->mColorFormats.push(portFormat.eColorFormat);
}
- CHECK_EQ(omx->freeNode(node), OK);
+ CHECK_EQ(omx->freeNode(node), (status_t)OK);
}
}
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/StagefrightMetadataRetriever.cpp b/media/libstagefright/StagefrightMetadataRetriever.cpp
index 9b2dec9..763a914 100644
--- a/media/libstagefright/StagefrightMetadataRetriever.cpp
+++ b/media/libstagefright/StagefrightMetadataRetriever.cpp
@@ -191,17 +191,26 @@ static VideoFrame *extractVideoFrameWithCodecFlags(
CHECK(meta->findInt32(kKeyWidth, &width));
CHECK(meta->findInt32(kKeyHeight, &height));
+ int32_t crop_left, crop_top, crop_right, crop_bottom;
+ if (!meta->findRect(
+ kKeyCropRect,
+ &crop_left, &crop_top, &crop_right, &crop_bottom)) {
+ crop_left = crop_top = 0;
+ crop_right = width - 1;
+ crop_bottom = height - 1;
+ }
+
int32_t rotationAngle;
if (!trackMeta->findInt32(kKeyRotation, &rotationAngle)) {
rotationAngle = 0; // By default, no rotation
}
VideoFrame *frame = new VideoFrame;
- frame->mWidth = width;
- frame->mHeight = height;
- frame->mDisplayWidth = width;
- frame->mDisplayHeight = height;
- frame->mSize = width * height * 2;
+ frame->mWidth = crop_right - crop_left + 1;
+ frame->mHeight = crop_bottom - crop_top + 1;
+ frame->mDisplayWidth = frame->mWidth;
+ frame->mDisplayHeight = frame->mHeight;
+ frame->mSize = frame->mWidth * frame->mHeight * 2;
frame->mData = new uint8_t[frame->mSize];
frame->mRotationAngle = rotationAngle;
@@ -213,10 +222,13 @@ static VideoFrame *extractVideoFrameWithCodecFlags(
CHECK(converter.isValid());
converter.convert(
- width, height,
(const uint8_t *)buffer->data() + buffer->range_offset(),
- 0,
- frame->mData, width * 2);
+ width, height,
+ crop_left, crop_top, crop_right, crop_bottom,
+ frame->mData,
+ frame->mWidth,
+ frame->mHeight,
+ 0, 0, frame->mWidth - 1, frame->mHeight - 1);
buffer->release();
buffer = NULL;
@@ -418,5 +430,4 @@ void StagefrightMetadataRetriever::parseMetaData() {
}
}
-
} // namespace android
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/codecs/avc/dec/AVCDecoder.cpp b/media/libstagefright/codecs/avc/dec/AVCDecoder.cpp
index 868c514..5bbba35 100644
--- a/media/libstagefright/codecs/avc/dec/AVCDecoder.cpp
+++ b/media/libstagefright/codecs/avc/dec/AVCDecoder.cpp
@@ -73,6 +73,7 @@ AVCDecoder::AVCDecoder(const sp<MediaSource> &source)
CHECK(mSource->getFormat()->findInt32(kKeyHeight, &height));
mFormat->setInt32(kKeyWidth, width);
mFormat->setInt32(kKeyHeight, height);
+ mFormat->setRect(kKeyCropRect, 0, 0, width - 1, height - 1);
mFormat->setInt32(kKeyColorFormat, OMX_COLOR_FormatYUV420Planar);
mFormat->setCString(kKeyDecoderComponent, "AVCDecoder");
@@ -418,16 +419,32 @@ status_t AVCDecoder::read(
crop_top = crop_left = 0;
}
- int32_t aligned_width = (crop_right - crop_left + 1 + 15) & ~15;
- int32_t aligned_height = (crop_bottom - crop_top + 1 + 15) & ~15;
+ int32_t prevCropLeft, prevCropTop;
+ int32_t prevCropRight, prevCropBottom;
+ if (!mFormat->findRect(
+ kKeyCropRect,
+ &prevCropLeft, &prevCropTop,
+ &prevCropRight, &prevCropBottom)) {
+ prevCropLeft = prevCropTop = 0;
+ prevCropRight = width - 1;
+ prevCropBottom = height - 1;
+ }
int32_t oldWidth, oldHeight;
CHECK(mFormat->findInt32(kKeyWidth, &oldWidth));
CHECK(mFormat->findInt32(kKeyHeight, &oldHeight));
- if (oldWidth != aligned_width || oldHeight != aligned_height) {
- mFormat->setInt32(kKeyWidth, aligned_width);
- mFormat->setInt32(kKeyHeight, aligned_height);
+ if (oldWidth != width || oldHeight != height
+ || prevCropLeft != crop_left
+ || prevCropTop != crop_top
+ || prevCropRight != crop_right
+ || prevCropBottom != crop_bottom) {
+ mFormat->setRect(
+ kKeyCropRect,
+ crop_left, crop_top, crop_right, crop_bottom);
+
+ mFormat->setInt32(kKeyWidth, width);
+ mFormat->setInt32(kKeyHeight, height);
err = INFO_FORMAT_CHANGED;
} else {
diff --git a/media/libstagefright/colorconversion/Android.mk b/media/libstagefright/colorconversion/Android.mk
index ef2dba0..62ba40f 100644
--- a/media/libstagefright/colorconversion/Android.mk
+++ b/media/libstagefright/colorconversion/Android.mk
@@ -9,20 +9,6 @@ LOCAL_C_INCLUDES := \
$(TOP)/frameworks/base/include/media/stagefright/openmax \
$(TOP)/hardware/msm7k
-LOCAL_SHARED_LIBRARIES := \
- libbinder \
- libmedia \
- libutils \
- libui \
- libcutils \
- libsurfaceflinger_client\
- libcamera_client
-
-# ifeq ($(TARGET_BOARD_PLATFORM),msm7k)
-ifeq ($(TARGET_PRODUCT),passion)
- LOCAL_CFLAGS += -DHAS_YCBCR420_SP_ADRENO
-endif
-
LOCAL_MODULE:= libstagefright_color_conversion
-include $(BUILD_SHARED_LIBRARY)
+include $(BUILD_STATIC_LIBRARY)
diff --git a/media/libstagefright/colorconversion/ColorConverter.cpp b/media/libstagefright/colorconversion/ColorConverter.cpp
index 5b16997..600f040 100644
--- a/media/libstagefright/colorconversion/ColorConverter.cpp
+++ b/media/libstagefright/colorconversion/ColorConverter.cpp
@@ -50,31 +50,64 @@ bool ColorConverter::isValid() const {
}
}
-void ColorConverter::convert(
+ColorConverter::BitmapParams::BitmapParams(
+ void *bits,
size_t width, size_t height,
- const void *srcBits, size_t srcSkip,
- void *dstBits, size_t dstSkip) {
+ size_t cropLeft, size_t cropTop,
+ size_t cropRight, size_t cropBottom)
+ : mBits(bits),
+ mWidth(width),
+ mHeight(height),
+ mCropLeft(cropLeft),
+ mCropTop(cropTop),
+ mCropRight(cropRight),
+ mCropBottom(cropBottom) {
+}
+
+size_t ColorConverter::BitmapParams::cropWidth() const {
+ return mCropRight - mCropLeft + 1;
+}
+
+size_t ColorConverter::BitmapParams::cropHeight() const {
+ return mCropBottom - mCropTop + 1;
+}
+
+void ColorConverter::convert(
+ const void *srcBits,
+ size_t srcWidth, size_t srcHeight,
+ size_t srcCropLeft, size_t srcCropTop,
+ size_t srcCropRight, size_t srcCropBottom,
+ void *dstBits,
+ size_t dstWidth, size_t dstHeight,
+ size_t dstCropLeft, size_t dstCropTop,
+ size_t dstCropRight, size_t dstCropBottom) {
CHECK_EQ(mDstFormat, OMX_COLOR_Format16bitRGB565);
+ BitmapParams src(
+ const_cast<void *>(srcBits),
+ srcWidth, srcHeight,
+ srcCropLeft, srcCropTop, srcCropRight, srcCropBottom);
+
+ BitmapParams dst(
+ dstBits,
+ dstWidth, dstHeight,
+ dstCropLeft, dstCropTop, dstCropRight, dstCropBottom);
+
switch (mSrcFormat) {
case OMX_COLOR_FormatYUV420Planar:
- convertYUV420Planar(
- width, height, srcBits, srcSkip, dstBits, dstSkip);
+ convertYUV420Planar(src, dst);
break;
case OMX_COLOR_FormatCbYCrY:
- convertCbYCrY(
- width, height, srcBits, srcSkip, dstBits, dstSkip);
+ convertCbYCrY(src, dst);
break;
case OMX_QCOM_COLOR_FormatYVU420SemiPlanar:
- convertQCOMYUV420SemiPlanar(
- width, height, srcBits, srcSkip, dstBits, dstSkip);
+ convertQCOMYUV420SemiPlanar(src, dst);
break;
case OMX_COLOR_FormatYUV420SemiPlanar:
- convertYUV420SemiPlanar(
- width, height, srcBits, srcSkip, dstBits, dstSkip);
+ convertYUV420SemiPlanar(src, dst);
break;
default:
@@ -86,25 +119,27 @@ void ColorConverter::convert(
}
void ColorConverter::convertCbYCrY(
- size_t width, size_t height,
- const void *srcBits, size_t srcSkip,
- void *dstBits, size_t dstSkip) {
- CHECK_EQ(srcSkip, 0); // Doesn't really make sense for YUV formats.
- CHECK(dstSkip >= width * 2);
- CHECK((dstSkip & 3) == 0);
+ const BitmapParams &src, const BitmapParams &dst) {
+ // XXX Untested
uint8_t *kAdjustedClip = initClip();
- uint32_t *dst_ptr = (uint32_t *)dstBits;
+ CHECK((src.mCropLeft & 1) == 0);
+ CHECK_EQ(src.cropWidth(), dst.cropWidth());
+ CHECK_EQ(src.cropHeight(), dst.cropHeight());
+
+ uint32_t *dst_ptr = (uint32_t *)dst.mBits
+ + (dst.mCropTop * dst.mWidth + dst.mCropLeft) / 2;
- const uint8_t *src = (const uint8_t *)srcBits;
+ const uint8_t *src_ptr = (const uint8_t *)src.mBits
+ + (src.mCropTop * dst.mWidth + src.mCropLeft) * 2;
- for (size_t y = 0; y < height; ++y) {
- for (size_t x = 0; x < width; x += 2) {
- signed y1 = (signed)src[2 * x + 1] - 16;
- signed y2 = (signed)src[2 * x + 3] - 16;
- signed u = (signed)src[2 * x] - 128;
- signed v = (signed)src[2 * x + 2] - 128;
+ for (size_t y = 0; y < src.cropHeight(); ++y) {
+ for (size_t x = 0; x < src.cropWidth(); x += 2) {
+ signed y1 = (signed)src_ptr[2 * x + 1] - 16;
+ signed y2 = (signed)src_ptr[2 * x + 3] - 16;
+ signed u = (signed)src_ptr[2 * x] - 128;
+ signed v = (signed)src_ptr[2 * x + 2] - 128;
signed u_b = u * 517;
signed u_g = -u * 100;
@@ -134,32 +169,35 @@ void ColorConverter::convertCbYCrY(
dst_ptr[x / 2] = (rgb2 << 16) | rgb1;
}
- src += width * 2;
- dst_ptr += dstSkip / 4;
+ src_ptr += src.mWidth * 2;
+ dst_ptr += dst.mWidth / 2;
}
}
void ColorConverter::convertYUV420Planar(
- size_t width, size_t height,
- const void *srcBits, size_t srcSkip,
- void *dstBits, size_t dstSkip) {
- CHECK_EQ(srcSkip, 0); // Doesn't really make sense for YUV formats.
- CHECK(dstSkip >= width * 2);
- CHECK((dstSkip & 3) == 0);
-
+ const BitmapParams &src, const BitmapParams &dst) {
uint8_t *kAdjustedClip = initClip();
- uint32_t *dst_ptr = (uint32_t *)dstBits;
- const uint8_t *src_y = (const uint8_t *)srcBits;
+ CHECK((dst.mWidth & 3) == 0);
+ CHECK((src.mCropLeft & 1) == 0);
+ CHECK_EQ(src.cropWidth(), dst.cropWidth());
+ CHECK_EQ(src.cropHeight(), dst.cropHeight());
+
+ uint32_t *dst_ptr = (uint32_t *)dst.mBits
+ + (dst.mCropTop * dst.mWidth + dst.mCropLeft) / 2;
+
+ const uint8_t *src_y =
+ (const uint8_t *)src.mBits + src.mCropTop * src.mWidth + src.mCropLeft;
const uint8_t *src_u =
- (const uint8_t *)src_y + width * height;
+ (const uint8_t *)src_y + src.mWidth * src.mHeight
+ + src.mCropTop * (src.mWidth / 2) + src.mCropLeft / 2;
const uint8_t *src_v =
- (const uint8_t *)src_u + (width / 2) * (height / 2);
+ src_u + (src.mWidth / 2) * (src.mHeight / 2);
- for (size_t y = 0; y < height; ++y) {
- for (size_t x = 0; x < width; x += 2) {
+ for (size_t y = 0; y < src.cropHeight(); ++y) {
+ for (size_t x = 0; x < src.cropWidth(); x += 2) {
// B = 1.164 * (Y - 16) + 2.018 * (U - 128)
// G = 1.164 * (Y - 16) - 0.813 * (V - 128) - 0.391 * (U - 128)
// R = 1.164 * (Y - 16) + 1.596 * (V - 128)
@@ -212,35 +250,38 @@ void ColorConverter::convertYUV420Planar(
dst_ptr[x / 2] = (rgb2 << 16) | rgb1;
}
- src_y += width;
+ src_y += src.mWidth;
if (y & 1) {
- src_u += width / 2;
- src_v += width / 2;
+ src_u += src.mWidth / 2;
+ src_v += src.mWidth / 2;
}
- dst_ptr += dstSkip / 4;
+ dst_ptr += dst.mWidth / 2;
}
}
void ColorConverter::convertQCOMYUV420SemiPlanar(
- size_t width, size_t height,
- const void *srcBits, size_t srcSkip,
- void *dstBits, size_t dstSkip) {
- CHECK_EQ(srcSkip, 0); // Doesn't really make sense for YUV formats.
- CHECK(dstSkip >= width * 2);
- CHECK((dstSkip & 3) == 0);
-
+ const BitmapParams &src, const BitmapParams &dst) {
uint8_t *kAdjustedClip = initClip();
- uint32_t *dst_ptr = (uint32_t *)dstBits;
- const uint8_t *src_y = (const uint8_t *)srcBits;
+ CHECK((dst.mWidth & 3) == 0);
+ CHECK((src.mCropLeft & 1) == 0);
+ CHECK_EQ(src.cropWidth(), dst.cropWidth());
+ CHECK_EQ(src.cropHeight(), dst.cropHeight());
+
+ uint32_t *dst_ptr = (uint32_t *)dst.mBits
+ + (dst.mCropTop * dst.mWidth + dst.mCropLeft) / 2;
+
+ const uint8_t *src_y =
+ (const uint8_t *)src.mBits + src.mCropTop * src.mWidth + src.mCropLeft;
const uint8_t *src_u =
- (const uint8_t *)src_y + width * height;
+ (const uint8_t *)src_y + src.mWidth * src.mHeight
+ + src.mCropTop * src.mWidth + src.mCropLeft;
- for (size_t y = 0; y < height; ++y) {
- for (size_t x = 0; x < width; x += 2) {
+ for (size_t y = 0; y < src.cropHeight(); ++y) {
+ for (size_t x = 0; x < src.cropWidth(); x += 2) {
signed y1 = (signed)src_y[x] - 16;
signed y2 = (signed)src_y[x + 1] - 16;
@@ -275,34 +316,39 @@ void ColorConverter::convertQCOMYUV420SemiPlanar(
dst_ptr[x / 2] = (rgb2 << 16) | rgb1;
}
- src_y += width;
+ src_y += src.mWidth;
if (y & 1) {
- src_u += width;
+ src_u += src.mWidth;
}
- dst_ptr += dstSkip / 4;
+ dst_ptr += dst.mWidth / 2;
}
}
void ColorConverter::convertYUV420SemiPlanar(
- size_t width, size_t height,
- const void *srcBits, size_t srcSkip,
- void *dstBits, size_t dstSkip) {
- CHECK_EQ(srcSkip, 0); // Doesn't really make sense for YUV formats.
- CHECK(dstSkip >= width * 2);
- CHECK((dstSkip & 3) == 0);
+ const BitmapParams &src, const BitmapParams &dst) {
+ // XXX Untested
uint8_t *kAdjustedClip = initClip();
- uint32_t *dst_ptr = (uint32_t *)dstBits;
- const uint8_t *src_y = (const uint8_t *)srcBits;
+ CHECK((dst.mWidth & 3) == 0);
+ CHECK((src.mCropLeft & 1) == 0);
+ CHECK_EQ(src.cropWidth(), dst.cropWidth());
+ CHECK_EQ(src.cropHeight(), dst.cropHeight());
+
+ uint32_t *dst_ptr = (uint32_t *)dst.mBits
+ + (dst.mCropTop * dst.mWidth + dst.mCropLeft) / 2;
+
+ const uint8_t *src_y =
+ (const uint8_t *)src.mBits + src.mCropTop * src.mWidth + src.mCropLeft;
const uint8_t *src_u =
- (const uint8_t *)src_y + width * height;
+ (const uint8_t *)src_y + src.mWidth * src.mHeight
+ + src.mCropTop * src.mWidth + src.mCropLeft;
- for (size_t y = 0; y < height; ++y) {
- for (size_t x = 0; x < width; x += 2) {
+ for (size_t y = 0; y < src.cropHeight(); ++y) {
+ for (size_t x = 0; x < src.cropWidth(); x += 2) {
signed y1 = (signed)src_y[x] - 16;
signed y2 = (signed)src_y[x + 1] - 16;
@@ -337,13 +383,13 @@ void ColorConverter::convertYUV420SemiPlanar(
dst_ptr[x / 2] = (rgb2 << 16) | rgb1;
}
- src_y += width;
+ src_y += src.mWidth;
if (y & 1) {
- src_u += width;
+ src_u += src.mWidth;
}
- dst_ptr += dstSkip / 4;
+ dst_ptr += dst.mWidth / 2;
}
}
diff --git a/media/libstagefright/colorconversion/SoftwareRenderer.cpp b/media/libstagefright/colorconversion/SoftwareRenderer.cpp
index acbea05..70408d7 100644
--- a/media/libstagefright/colorconversion/SoftwareRenderer.cpp
+++ b/media/libstagefright/colorconversion/SoftwareRenderer.cpp
@@ -21,55 +21,41 @@
#include <binder/MemoryHeapBase.h>
#include <binder/MemoryHeapPmem.h>
-#include <media/stagefright/MediaDebug.h>
+#include <media/stagefright/foundation/ADebug.h>
+#include <media/stagefright/MetaData.h>
#include <surfaceflinger/Surface.h>
#include <ui/android_native_buffer.h>
#include <ui/GraphicBufferMapper.h>
-// XXX: Temporary hack to allow referencing the _ADRENO pixel format here.
-#include <libgralloc-qsd8k/gralloc_priv.h>
-
namespace android {
SoftwareRenderer::SoftwareRenderer(
- OMX_COLOR_FORMATTYPE colorFormat,
- const sp<Surface> &surface,
- size_t displayWidth, size_t displayHeight,
- size_t decodedWidth, size_t decodedHeight,
- int32_t rotationDegrees)
- : mColorFormat(colorFormat),
- mConverter(NULL),
+ const sp<Surface> &surface, const sp<MetaData> &meta)
+ : mConverter(NULL),
mYUVMode(None),
- mSurface(surface),
- mDisplayWidth(displayWidth),
- mDisplayHeight(displayHeight),
- mDecodedWidth(decodedWidth),
- mDecodedHeight(decodedHeight) {
- LOGI("input format = %d", mColorFormat);
- LOGI("display = %d x %d, decoded = %d x %d",
- mDisplayWidth, mDisplayHeight, mDecodedWidth, mDecodedHeight);
-
- mDecodedWidth = mDisplayWidth;
- mDecodedHeight = mDisplayHeight;
+ mSurface(surface) {
+ int32_t tmp;
+ CHECK(meta->findInt32(kKeyColorFormat, &tmp));
+ mColorFormat = (OMX_COLOR_FORMATTYPE)tmp;
+
+ CHECK(meta->findInt32(kKeyWidth, &mWidth));
+ CHECK(meta->findInt32(kKeyHeight, &mHeight));
+
+ if (!meta->findRect(
+ kKeyCropRect,
+ &mCropLeft, &mCropTop, &mCropRight, &mCropBottom)) {
+ mCropLeft = mCropTop = 0;
+ mCropRight = mWidth - 1;
+ mCropBottom = mHeight - 1;
+ }
+
+ int32_t rotationDegrees;
+ if (!meta->findInt32(kKeyRotation, &rotationDegrees)) {
+ rotationDegrees = 0;
+ }
int halFormat;
switch (mColorFormat) {
-#if HAS_YCBCR420_SP_ADRENO
- case OMX_COLOR_FormatYUV420Planar:
- {
- halFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO;
- mYUVMode = YUV420ToYUV420sp;
- break;
- }
-
- case 0x7fa30c00:
- {
- halFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO;
- mYUVMode = YUV420spToYUV420sp;
- break;
- }
-#endif
-
default:
halFormat = HAL_PIXEL_FORMAT_RGB_565;
@@ -80,8 +66,8 @@ SoftwareRenderer::SoftwareRenderer(
}
CHECK(mSurface.get() != NULL);
- CHECK(mDecodedWidth > 0);
- CHECK(mDecodedHeight > 0);
+ CHECK(mWidth > 0);
+ CHECK(mHeight > 0);
CHECK(mConverter == NULL || mConverter->isValid());
CHECK_EQ(0,
@@ -94,7 +80,9 @@ SoftwareRenderer::SoftwareRenderer(
// Width must be multiple of 32???
CHECK_EQ(0, native_window_set_buffers_geometry(
- mSurface.get(), mDecodedWidth, mDecodedHeight,
+ mSurface.get(),
+ mCropRight - mCropLeft + 1,
+ mCropBottom - mCropTop + 1,
halFormat));
uint32_t transform;
@@ -117,10 +105,6 @@ SoftwareRenderer::~SoftwareRenderer() {
mConverter = NULL;
}
-static inline size_t ALIGN(size_t x, size_t alignment) {
- return (x + alignment - 1) & ~(alignment - 1);
-}
-
void SoftwareRenderer::render(
const void *data, size_t size, void *platformPrivate) {
android_native_buffer_t *buf;
@@ -134,7 +118,7 @@ void SoftwareRenderer::render(
GraphicBufferMapper &mapper = GraphicBufferMapper::get();
- Rect bounds(mDecodedWidth, mDecodedHeight);
+ Rect bounds(mWidth, mHeight);
void *dst;
CHECK_EQ(0, mapper.lock(
@@ -142,69 +126,16 @@ void SoftwareRenderer::render(
if (mConverter) {
mConverter->convert(
- mDecodedWidth, mDecodedHeight,
- data, 0, dst, buf->stride * 2);
- } else if (mYUVMode == YUV420spToYUV420sp) {
- // Input and output are both YUV420sp, but the alignment requirements
- // are different.
- size_t srcYStride = mDecodedWidth;
- const uint8_t *srcY = (const uint8_t *)data;
- uint8_t *dstY = (uint8_t *)dst;
- for (size_t i = 0; i < mDecodedHeight; ++i) {
- memcpy(dstY, srcY, mDecodedWidth);
- srcY += srcYStride;
- dstY += buf->stride;
- }
-
- size_t srcUVStride = (mDecodedWidth + 1) & ~1;
- size_t dstUVStride = ALIGN(mDecodedWidth / 2, 32) * 2;
-
- const uint8_t *srcUV = (const uint8_t *)data
- + mDecodedHeight * mDecodedWidth;
-
- size_t dstUVOffset = ALIGN(ALIGN(mDecodedHeight, 32) * buf->stride, 4096);
- uint8_t *dstUV = (uint8_t *)dst + dstUVOffset;
-
- for (size_t i = 0; i < (mDecodedHeight + 1) / 2; ++i) {
- memcpy(dstUV, srcUV, (mDecodedWidth + 1) & ~1);
- srcUV += srcUVStride;
- dstUV += dstUVStride;
- }
- } else if (mYUVMode == YUV420ToYUV420sp) {
- // Input is YUV420 planar, output is YUV420sp, adhere to proper
- // alignment requirements.
- size_t srcYStride = mDecodedWidth;
- const uint8_t *srcY = (const uint8_t *)data;
- uint8_t *dstY = (uint8_t *)dst;
- for (size_t i = 0; i < mDecodedHeight; ++i) {
- memcpy(dstY, srcY, mDecodedWidth);
- srcY += srcYStride;
- dstY += buf->stride;
- }
-
- size_t srcUVStride = (mDecodedWidth + 1) / 2;
- size_t dstUVStride = ALIGN(mDecodedWidth / 2, 32) * 2;
-
- const uint8_t *srcU = (const uint8_t *)data
- + mDecodedHeight * mDecodedWidth;
-
- const uint8_t *srcV =
- srcU + ((mDecodedWidth + 1) / 2) * ((mDecodedHeight + 1) / 2);
-
- size_t dstUVOffset = ALIGN(ALIGN(mDecodedHeight, 32) * buf->stride, 4096);
- uint8_t *dstUV = (uint8_t *)dst + dstUVOffset;
-
- for (size_t i = 0; i < (mDecodedHeight + 1) / 2; ++i) {
- for (size_t j = 0; j < (mDecodedWidth + 1) / 2; ++j) {
- dstUV[2 * j + 1] = srcU[j];
- dstUV[2 * j] = srcV[j];
- }
- srcU += srcUVStride;
- srcV += srcUVStride;
- dstUV += dstUVStride;
- }
+ data,
+ mWidth, mHeight,
+ mCropLeft, mCropTop, mCropRight, mCropBottom,
+ dst,
+ buf->stride, buf->height,
+ 0, 0,
+ mCropRight - mCropLeft,
+ mCropBottom - mCropTop);
} else {
- memcpy(dst, data, size);
+ TRESPASS();
}
CHECK_EQ(0, mapper.unlock(buf->handle));
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/AwesomePlayer.h b/media/libstagefright/include/AwesomePlayer.h
index 4e63b7a..e33f467 100644
--- a/media/libstagefright/include/AwesomePlayer.h
+++ b/media/libstagefright/include/AwesomePlayer.h
@@ -88,11 +88,6 @@ struct AwesomePlayer {
status_t seekTo(int64_t timeUs);
- status_t getVideoDimensions(int32_t *width, int32_t *height) const;
-
- status_t suspend();
- status_t resume();
-
// This is a mask of MediaExtractor::Flags.
uint32_t flags() const;
@@ -153,7 +148,6 @@ private:
uint32_t mFlags;
uint32_t mExtractorFlags;
- int32_t mVideoWidth, mVideoHeight;
int64_t mTimeSourceDeltaUs;
int64_t mVideoTimeUs;
@@ -187,7 +181,6 @@ private:
void postCheckAudioStatusEvent_l();
status_t play_l();
- MediaBuffer *mLastVideoBuffer;
MediaBuffer *mVideoBuffer;
sp<NuHTTPDataSource> mConnectingDataSource;
@@ -198,32 +191,6 @@ private:
sp<ARTPSession> mRTPSession;
sp<UDPPusher> mRTPPusher, mRTCPPusher;
- struct SuspensionState {
- String8 mUri;
- KeyedVector<String8, String8> mUriHeaders;
- sp<DataSource> mFileSource;
-
- uint32_t mFlags;
- int64_t mPositionUs;
-
- void *mLastVideoFrame;
- size_t mLastVideoFrameSize;
- int32_t mColorFormat;
- int32_t mVideoWidth, mVideoHeight;
- int32_t mDecodedWidth, mDecodedHeight;
-
- SuspensionState()
- : mLastVideoFrame(NULL) {
- }
-
- ~SuspensionState() {
- if (mLastVideoFrame) {
- free(mLastVideoFrame);
- mLastVideoFrame = NULL;
- }
- }
- } *mSuspensionState;
-
DrmManagerClient *mDrmManagerClient;
DecryptHandle *mDecryptHandle;
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/SoftwareRenderer.h b/media/libstagefright/include/SoftwareRenderer.h
index 9cafc68..90d3fe1 100644
--- a/media/libstagefright/include/SoftwareRenderer.h
+++ b/media/libstagefright/include/SoftwareRenderer.h
@@ -23,16 +23,13 @@
namespace android {
+struct MetaData;
class Surface;
class SoftwareRenderer {
public:
SoftwareRenderer(
- OMX_COLOR_FORMATTYPE colorFormat,
- const sp<Surface> &surface,
- size_t displayWidth, size_t displayHeight,
- size_t decodedWidth, size_t decodedHeight,
- int32_t rotationDegrees);
+ const sp<Surface> &surface, const sp<MetaData> &meta);
~SoftwareRenderer();
@@ -42,16 +39,14 @@ public:
private:
enum YUVMode {
None,
- YUV420ToYUV420sp,
- YUV420spToYUV420sp,
};
OMX_COLOR_FORMATTYPE mColorFormat;
ColorConverter *mConverter;
YUVMode mYUVMode;
sp<Surface> mSurface;
- size_t mDisplayWidth, mDisplayHeight;
- size_t mDecodedWidth, mDecodedHeight;
+ int32_t mWidth, mHeight;
+ int32_t mCropLeft, mCropTop, mCropRight, mCropBottom;
SoftwareRenderer(const SoftwareRenderer &);
SoftwareRenderer &operator=(const SoftwareRenderer &);
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/omx/Android.mk b/media/libstagefright/omx/Android.mk
index ead1675..6e069c8 100644
--- a/media/libstagefright/omx/Android.mk
+++ b/media/libstagefright/omx/Android.mk
@@ -31,7 +31,6 @@ LOCAL_SHARED_LIBRARIES := \
libutils \
libui \
libcutils \
- libstagefright_color_conversion
ifneq ($(BUILD_WITHOUT_PV),true)
LOCAL_SHARED_LIBRARIES += \
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();