video_transformation.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef MEDIA_BASE_VIDEO_TRANSFORMATION_H_
  5. #define MEDIA_BASE_VIDEO_TRANSFORMATION_H_
  6. #include <string>
  7. #include "base/numerics/math_constants.h"
  8. #include "media/base/media_export.h"
  9. namespace media {
  10. // Enumeration to represent 90 degree video rotation for MP4 videos
  11. // where it can be rotated by 90 degree intervals.
  12. enum VideoRotation : int {
  13. VIDEO_ROTATION_0 = 0,
  14. VIDEO_ROTATION_90 = 90,
  15. VIDEO_ROTATION_180 = 180,
  16. VIDEO_ROTATION_270 = 270,
  17. VIDEO_ROTATION_MAX = VIDEO_ROTATION_270
  18. };
  19. // Stores frame rotation & mirroring values. These are usually calculated from
  20. // a rotation matrix from a demuxer, and we only support 90 degree rotation
  21. // increments.
  22. struct MEDIA_EXPORT VideoTransformation {
  23. static VideoTransformation FromFFmpegDisplayMatrix(int32_t* matrix);
  24. constexpr VideoTransformation(VideoRotation rotation, bool mirrored)
  25. : rotation(rotation), mirrored(mirrored) {}
  26. constexpr VideoTransformation(VideoRotation r)
  27. : VideoTransformation(r, false) {}
  28. constexpr VideoTransformation()
  29. : VideoTransformation(VIDEO_ROTATION_0, false) {}
  30. // Rotation by angle Θ is represented in the matrix as:
  31. // [ cos(Θ), -sin(Θ)]
  32. // [ sin(Θ), cos(Θ)]
  33. // A vertical flip is represented by the cosine's having opposite signs
  34. // and a horizontal flip is represented by the sine's having the same sign.
  35. VideoTransformation(int32_t matrix[4]);
  36. // The video rotation value, in 90 degree steps.
  37. VideoRotation rotation;
  38. // Whether the video should be flipped about its Y axis.
  39. // This transformation takes place _after_ rotation, since they are not
  40. // commutative.
  41. bool mirrored;
  42. };
  43. MEDIA_EXPORT bool operator==(const struct VideoTransformation& first,
  44. const struct VideoTransformation& second);
  45. constexpr VideoTransformation kNoTransformation = VideoTransformation();
  46. std::string MEDIA_EXPORT VideoRotationToString(VideoRotation rotation);
  47. } // namespace media
  48. #endif // MEDIA_BASE_VIDEO_TRANSFORMATION_H_