summaryrefslogtreecommitdiffstats
path: root/media/libstagefright
diff options
context:
space:
mode:
authorAndreas Huber <andih@google.com>2012-12-03 15:20:40 -0800
committerAndreas Huber <andih@google.com>2012-12-05 10:34:34 -0800
commit516dacfb02d0b0eafe21114330c98ce0e7d90da9 (patch)
treed52b7097f333fa4d010f224849897b9808b6463a /media/libstagefright
parent88e672043a0671557d9c0877e069dc95de0d8cb0 (diff)
downloadframeworks_av-516dacfb02d0b0eafe21114330c98ce0e7d90da9.zip
frameworks_av-516dacfb02d0b0eafe21114330c98ce0e7d90da9.tar.gz
frameworks_av-516dacfb02d0b0eafe21114330c98ce0e7d90da9.tar.bz2
Respect sample aspect ratio in NuPlayer.
related-to-bug: 7569402 Change-Id: I302de95d83b180bd2dc72ddd0c69a665dbce2527
Diffstat (limited to 'media/libstagefright')
-rw-r--r--media/libstagefright/ACodec.cpp14
-rw-r--r--media/libstagefright/Utils.cpp14
-rw-r--r--media/libstagefright/avc_utils.cpp76
-rw-r--r--media/libstagefright/include/avc_utils.h5
4 files changed, 100 insertions, 9 deletions
diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp
index 2a7b2ae..2b20ab0 100644
--- a/media/libstagefright/ACodec.cpp
+++ b/media/libstagefright/ACodec.cpp
@@ -966,17 +966,23 @@ status_t ACodec::configureCodec(
err = INVALID_OPERATION;
} else {
if (encoder) {
- if (!msg->findInt32("flac-compression-level", &compressionLevel)) {
+ if (!msg->findInt32(
+ "flac-compression-level", &compressionLevel)) {
compressionLevel = 5;// default FLAC compression level
} else if (compressionLevel < 0) {
- ALOGW("compression level %d outside [0..8] range, using 0", compressionLevel);
+ ALOGW("compression level %d outside [0..8] range, "
+ "using 0",
+ compressionLevel);
compressionLevel = 0;
} else if (compressionLevel > 8) {
- ALOGW("compression level %d outside [0..8] range, using 8", compressionLevel);
+ ALOGW("compression level %d outside [0..8] range, "
+ "using 8",
+ compressionLevel);
compressionLevel = 8;
}
}
- err = setupFlacCodec(encoder, numChannels, sampleRate, compressionLevel);
+ err = setupFlacCodec(
+ encoder, numChannels, sampleRate, compressionLevel);
}
} else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_RAW)) {
int32_t numChannels, sampleRate;
diff --git a/media/libstagefright/Utils.cpp b/media/libstagefright/Utils.cpp
index 74e9222..1a6ff4b 100644
--- a/media/libstagefright/Utils.cpp
+++ b/media/libstagefright/Utils.cpp
@@ -85,6 +85,13 @@ status_t convertMetaDataToMessage(
msg->setInt32("width", width);
msg->setInt32("height", height);
+
+ int32_t sarWidth, sarHeight;
+ if (meta->findInt32(kKeySARWidth, &sarWidth)
+ && meta->findInt32(kKeySARHeight, &sarHeight)) {
+ msg->setInt32("sar-width", sarWidth);
+ msg->setInt32("sar-height", sarHeight);
+ }
} else if (!strncasecmp("audio/", mime, 6)) {
int32_t numChannels, sampleRate;
CHECK(meta->findInt32(kKeyChannelCount, &numChannels));
@@ -372,6 +379,13 @@ void convertMessageToMetaData(const sp<AMessage> &msg, sp<MetaData> &meta) {
} else {
ALOGW("did not find width and/or height");
}
+
+ int32_t sarWidth, sarHeight;
+ if (msg->findInt32("sar-width", &sarWidth)
+ && msg->findInt32("sar-height", &sarHeight)) {
+ meta->setInt32(kKeySARWidth, sarWidth);
+ meta->setInt32(kKeySARHeight, sarHeight);
+ }
} else if (mime.startsWith("audio/")) {
int32_t numChannels;
if (msg->findInt32("channel-count", &numChannels)) {
diff --git a/media/libstagefright/avc_utils.cpp b/media/libstagefright/avc_utils.cpp
index a141752..b822868 100644
--- a/media/libstagefright/avc_utils.cpp
+++ b/media/libstagefright/avc_utils.cpp
@@ -22,6 +22,7 @@
#include <media/stagefright/foundation/ABitReader.h>
#include <media/stagefright/foundation/ADebug.h>
+#include <media/stagefright/foundation/hexdump.h>
#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/MediaErrors.h>
#include <media/stagefright/MetaData.h>
@@ -41,7 +42,9 @@ unsigned parseUE(ABitReader *br) {
// Determine video dimensions from the sequence parameterset.
void FindAVCDimensions(
- const sp<ABuffer> &seqParamSet, int32_t *width, int32_t *height) {
+ const sp<ABuffer> &seqParamSet,
+ int32_t *width, int32_t *height,
+ int32_t *sarWidth, int32_t *sarHeight) {
ABitReader br(seqParamSet->data() + 1, seqParamSet->size() - 1);
unsigned profile_idc = br.getBits(8);
@@ -129,6 +132,48 @@ void FindAVCDimensions(
*height -=
(frame_crop_top_offset + frame_crop_bottom_offset) * cropUnitY;
}
+
+ if (sarWidth != NULL) {
+ *sarWidth = 0;
+ }
+
+ if (sarHeight != NULL) {
+ *sarHeight = 0;
+ }
+
+ if (br.getBits(1)) { // vui_parameters_present_flag
+ unsigned sar_width = 0, sar_height = 0;
+
+ if (br.getBits(1)) { // aspect_ratio_info_present_flag
+ unsigned aspect_ratio_idc = br.getBits(8);
+
+ if (aspect_ratio_idc == 255 /* extendedSAR */) {
+ sar_width = br.getBits(16);
+ sar_height = br.getBits(16);
+ } else if (aspect_ratio_idc > 0 && aspect_ratio_idc < 14) {
+ static const int32_t kFixedSARWidth[] = {
+ 1, 12, 10, 16, 40, 24, 20, 32, 80, 18, 15, 64, 160
+ };
+
+ static const int32_t kFixedSARHeight[] = {
+ 1, 11, 11, 11, 33, 11, 11, 11, 33, 11, 11, 33, 99
+ };
+
+ sar_width = kFixedSARWidth[aspect_ratio_idc - 1];
+ sar_height = kFixedSARHeight[aspect_ratio_idc - 1];
+ }
+ }
+
+ ALOGV("sample aspect ratio = %u : %u", sar_width, sar_height);
+
+ if (sarWidth != NULL) {
+ *sarWidth = sar_width;
+ }
+
+ if (sarHeight != NULL) {
+ *sarHeight = sar_height;
+ }
+ }
}
status_t getNextNALUnit(
@@ -254,7 +299,9 @@ sp<MetaData> MakeAVCCodecSpecificData(const sp<ABuffer> &accessUnit) {
}
int32_t width, height;
- FindAVCDimensions(seqParamSet, &width, &height);
+ int32_t sarWidth, sarHeight;
+ FindAVCDimensions(
+ seqParamSet, &width, &height, &sarWidth, &sarHeight);
size_t stopOffset;
sp<ABuffer> picParamSet = FindNAL(data, size, 8, &stopOffset);
@@ -301,8 +348,29 @@ sp<MetaData> MakeAVCCodecSpecificData(const sp<ABuffer> &accessUnit) {
meta->setInt32(kKeyWidth, width);
meta->setInt32(kKeyHeight, height);
- ALOGI("found AVC codec config (%d x %d, %s-profile level %d.%d)",
- width, height, AVCProfileToString(profile), level / 10, level % 10);
+ if (sarWidth > 1 || sarHeight > 1) {
+ // We treat 0:0 (unspecified) as 1:1.
+
+ meta->setInt32(kKeySARWidth, sarWidth);
+ meta->setInt32(kKeySARHeight, sarHeight);
+
+ ALOGI("found AVC codec config (%d x %d, %s-profile level %d.%d) "
+ "SAR %d : %d",
+ width,
+ height,
+ AVCProfileToString(profile),
+ level / 10,
+ level % 10,
+ sarWidth,
+ sarHeight);
+ } else {
+ ALOGI("found AVC codec config (%d x %d, %s-profile level %d.%d)",
+ width,
+ height,
+ AVCProfileToString(profile),
+ level / 10,
+ level % 10);
+ }
return meta;
}
diff --git a/media/libstagefright/include/avc_utils.h b/media/libstagefright/include/avc_utils.h
index e418822..d517320 100644
--- a/media/libstagefright/include/avc_utils.h
+++ b/media/libstagefright/include/avc_utils.h
@@ -36,8 +36,11 @@ enum {
kAVCProfileCAVLC444Intra = 0x2c
};
+// Optionally returns sample aspect ratio as well.
void FindAVCDimensions(
- const sp<ABuffer> &seqParamSet, int32_t *width, int32_t *height);
+ const sp<ABuffer> &seqParamSet,
+ int32_t *width, int32_t *height,
+ int32_t *sarWidth = NULL, int32_t *sarHeight = NULL);
unsigned parseUE(ABitReader *br);