Skip to content

Commit

Permalink
StVideoQueue - read rotation angle from stream side data
Browse files Browse the repository at this point in the history
  • Loading branch information
gkv311 committed Feb 23, 2017
1 parent 7631318 commit 0b40285
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
37 changes: 34 additions & 3 deletions StMoviePlayer/StVideo/StVideoQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ StVideoQueue::StVideoQueue(const StHandle<StGLTextureQueue>& theTextureQueue,
myAvDiscard(AVDISCARD_DEFAULT),
myFramePts(0.0),
myPixelRatio(1.0f),
myHParallax(0),
myRotateDeg(0),
//
myVideoClock(0.0),
//
Expand Down Expand Up @@ -218,6 +220,8 @@ namespace {
const char* name;
};

static const StCString THE_ROTATE_KEY = stCString("rotate");

static const StCString THE_SRC_MODE_KEY = stCString("STEREO_MODE");
static const StCString THE_SRC_MODE_KEY_WMV = stCString("StereoscopicLayout");

Expand Down Expand Up @@ -408,6 +412,22 @@ bool StVideoQueue::init(AVFormatContext* theFormatCtx,
myHParallax = (int )stStringToLong(aValue.toCString(), 10, aCLocale);
}

// we can read information from Display Matrix in side data or from metadata key
myRotateDeg = 0;
#if(LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(55, 0, 0))
if(const uint8_t* aDispMatrix = av_stream_get_side_data(myStream, AV_PKT_DATA_DISPLAYMATRIX, NULL)) {
const double aRotDeg = -av_display_rotation_get((const int32_t* )aDispMatrix);
if(!st::isNaN(aRotDeg)) {
myRotateDeg = -int(aRotDeg - 360 * std::floor(aRotDeg / 360 + 0.9 / 360));
}
}
#else
if(stAV::meta::readTag(myStream, THE_ROTATE_KEY, aValue)) {
StCLocale aCLocale;
myRotateDeg = (int )-stStringToLong(aValue.toCString(), 10, aCLocale);
}
#endif

// stereoscopic mode tags
myStFormatInStream = is720in1080 ? StFormat_Tiled4x : StFormat_AUTO;
if(stAV::meta::readTag(myFormatCtx, THE_SRC_MODE_KEY, aValue)
Expand Down Expand Up @@ -862,14 +882,23 @@ void StVideoQueue::decodeLoop() {

// we currently allow to override source format stored in metadata
#ifdef ST_AV_NEWSTEREO
AVFrameSideData* aSideData = av_frame_get_side_data(myFrame.Frame, AV_FRAME_DATA_STEREO3D);
if(aSideData != NULL) {
AVStereo3D* aStereo = (AVStereo3D* )aSideData->data;
if(AVFrameSideData* aSideDataS3d = av_frame_get_side_data(myFrame.Frame, AV_FRAME_DATA_STEREO3D)) {
AVStereo3D* aStereo = (AVStereo3D* )aSideDataS3d->data;
myStFormatInStream = stAV::stereo3dAvToSt(aStereo->type);
if(aStereo->flags & AV_STEREO3D_FLAG_INVERT) {
myStFormatInStream = st::formatReversed(myStFormatInStream);
}
}
#endif
#if(LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(55, 0, 0))
if(const AVFrameSideData* aSideDataRot = av_frame_get_side_data(myFrame.Frame, AV_FRAME_DATA_DISPLAYMATRIX)) {
if(aSideDataRot->size >= 9 * sizeof(int32_t)) {
const double aRotDeg = -av_display_rotation_get((const int32_t* )aSideDataRot->data);
if(!st::isNaN(aRotDeg)) {
myRotateDeg = -int(aRotDeg - 360 * std::floor(aRotDeg / 360 + 0.9 / 360));
}
}
}
#endif
if(stAV::meta::readTag(myFrame.Frame, THE_SRC_MODE_KEY, aTagValue)) {
for(size_t aSrcId = 0;; ++aSrcId) {
Expand Down Expand Up @@ -907,6 +936,7 @@ void StVideoQueue::decodeLoop() {
StHandle<StStereoParams> aParams = aPacket->getSource();
if(!aParams.isNull()) {
aParams->setSeparationNeutral(myHParallax);
aParams->setZRotateZero((float )myRotateDeg);
}
isStarted = false;
}
Expand Down Expand Up @@ -951,6 +981,7 @@ void StVideoQueue::decodeLoop() {
StHandle<StStereoParams> aParams = aPacket->getSource();
if(!aParams.isNull()) {
aParams->setSeparationNeutral(myHParallax);
aParams->setZRotateZero((float )myRotateDeg);
}
isStarted = false;
}
Expand Down
1 change: 1 addition & 0 deletions StMoviePlayer/StVideo/StVideoQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ class StVideoQueue : public StAVPacketQueue {
double myFramePts;
GLfloat myPixelRatio; //!< pixel aspect ratio
int myHParallax; //!< horizontal parallax in pixels stored in metadata
int myRotateDeg; //!< rotate angle in degrees

double myVideoClock; //!< synchronization variable

Expand Down
4 changes: 4 additions & 0 deletions include/StAV/stAV.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ extern "C" {
#include <libavutil/stereo3d.h>
#endif

#if(LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(55, 0, 0))
#include <libavutil/display.h>
#endif

#ifdef _MSC_VER
#pragma warning(default : 4244)
#endif
Expand Down
14 changes: 14 additions & 0 deletions include/stTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#endif

#include <cmath> // fabs
#include <cfloat>
#include <cstddef> // size_t, NULL
#include <cstdlib>
#include <cstring> // for memcpy
Expand Down Expand Up @@ -542,6 +543,19 @@ inline int getEvenNumber(const int number) {
return isOddNumber(number) ? (number + 1) : number;
}

namespace st {
/**
* Return true for NaN.
*/
inline bool isNaN(double theValue) {
#if defined(_MSC_VER)
return ::_isnan(theValue) != 0;
#else
return std::isnan(theValue);
#endif
}
}

#include <StTemplates/StTemplates.h> // include commonly-used templates

/**
Expand Down

0 comments on commit 0b40285

Please sign in to comment.