Bug 1228601 - [Part1] Store only supported video rotation informatin into VideoInfo.; r=mattwoodrow draft
authorKilik Kuo <kikuo@mozilla.com>
Fri, 13 May 2016 02:17:39 +0800
changeset 372686 a9b294ee62b38bb950aa6a259b1874224e560c1c
parent 371902 4d63dde701b47b8661ab7990f197b6b60e543839
child 372687 7e64145e6101541690520a756ae6498ded52eebc
push id19561
push userkikuo@mozilla.com
push dateMon, 30 May 2016 03:00:41 +0000
reviewersmattwoodrow
bugs1228601
milestone49.0a1
Bug 1228601 - [Part1] Store only supported video rotation informatin into VideoInfo.; r=mattwoodrow MozReview-Commit-ID: GF1PpJGkGyA
dom/media/MediaInfo.h
media/libstagefright/binding/DecoderData.cpp
--- a/dom/media/MediaInfo.h
+++ b/dom/media/MediaInfo.h
@@ -172,40 +172,48 @@ protected:
 
 private:
   TrackType mType;
 };
 
 // Stores info relevant to presenting media frames.
 class VideoInfo : public TrackInfo {
 public:
+  enum Rotation {
+    kDegree_0 = 0,
+    kDegree_90 = 90,
+    kDegree_180 = 180,
+    kDegree_270 = 270,
+  };
   VideoInfo()
     : VideoInfo(-1, -1)
   {
   }
 
   VideoInfo(int32_t aWidth, int32_t aHeight)
     : TrackInfo(kVideoTrack, NS_LITERAL_STRING("2"), NS_LITERAL_STRING("main"),
                 EmptyString(), EmptyString(), true, 2)
     , mDisplay(nsIntSize(aWidth, aHeight))
     , mStereoMode(StereoMode::MONO)
     , mImage(nsIntSize(aWidth, aHeight))
     , mCodecSpecificConfig(new MediaByteBuffer)
     , mExtraData(new MediaByteBuffer)
+    , mRotation(kDegree_0)
     , mImageRect(nsIntRect(0, 0, aWidth, aHeight))
   {
   }
 
   VideoInfo(const VideoInfo& aOther)
     : TrackInfo(aOther)
     , mDisplay(aOther.mDisplay)
     , mStereoMode(aOther.mStereoMode)
     , mImage(aOther.mImage)
     , mCodecSpecificConfig(aOther.mCodecSpecificConfig)
     , mExtraData(aOther.mExtraData)
+    , mRotation(aOther.mRotation)
     , mImageRect(aOther.mImageRect)
   {
   }
 
   bool IsValid() const override
   {
     return mDisplay.width > 0 && mDisplay.height > 0;
   }
@@ -254,29 +262,48 @@ public:
     nsIntRect imageRect = ImageRect();
     imageRect.x = (imageRect.x * aWidth) / mImage.width;
     imageRect.y = (imageRect.y * aHeight) / mImage.height;
     imageRect.width = (aWidth * imageRect.width) / mImage.width;
     imageRect.height = (aHeight * imageRect.height) / mImage.height;
     return imageRect;
   }
 
+  Rotation ToSupportedRotation(int32_t aDegree)
+  {
+    switch (aDegree) {
+      case 90:
+        return kDegree_90;
+      case 180:
+        return kDegree_180;
+      case 270:
+        return kDegree_270;
+      default:
+        NS_WARN_IF_FALSE(aDegree == 0, "Invalid rotation degree, ignored");
+        return kDegree_0;
+    }
+  }
+
   // Size in pixels at which the video is rendered. This is after it has
   // been scaled by its aspect ratio.
   nsIntSize mDisplay;
 
   // Indicates the frame layout for single track stereo videos.
   StereoMode mStereoMode;
 
   // Size of the decoded video's image.
   nsIntSize mImage;
 
   RefPtr<MediaByteBuffer> mCodecSpecificConfig;
   RefPtr<MediaByteBuffer> mExtraData;
 
+  // Describing how many degrees video frames should be rotated in clock-wise to
+  // get correct view.
+  Rotation mRotation;
+
 private:
   // mImage may be cropped; currently only used with the WebM container.
   // A negative width or height indicate that no cropping is to occur.
   nsIntRect mImageRect;
 };
 
 class AudioInfo : public TrackInfo {
 public:
--- a/media/libstagefright/binding/DecoderData.cpp
+++ b/media/libstagefright/binding/DecoderData.cpp
@@ -159,16 +159,17 @@ MP4AudioInfo::IsValid() const
 void
 MP4VideoInfo::Update(const MetaData* aMetaData, const char* aMimeType)
 {
   UpdateTrackInfo(*this, aMetaData, aMimeType);
   mDisplay.width = FindInt32(aMetaData, kKeyDisplayWidth);
   mDisplay.height = FindInt32(aMetaData, kKeyDisplayHeight);
   mImage.width = FindInt32(aMetaData, kKeyWidth);
   mImage.height = FindInt32(aMetaData, kKeyHeight);
+  mRotation = VideoInfo::ToSupportedRotation(FindInt32(aMetaData, kKeyRotation));
 
   FindData(aMetaData, kKeyAVCC, mExtraData);
   if (!mExtraData->Length()) {
     if (FindData(aMetaData, kKeyESDS, mExtraData)) {
       ESDS esds(mExtraData->Elements(), mExtraData->Length());
 
       const void* data;
       size_t size;