您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

rtp-ext-video-orientation.c 4.0KB

10 个月前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "rtp-ext.h"
  2. #include <inttypes.h>
  3. #include <stdint.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <assert.h>
  7. #include <stdio.h>
  8. // https://www.arib.or.jp/english/html/overview/doc/STD-T63V12_00/5_Appendix/Rel13/26/26114-d30.pdf
  9. /*
  10. 7.4.5 Coordination of Video Orientation
  11. Coordination of Video Orientation consists in signalling of the current orientation of the image captured on the sender
  12. side to the receiver for appropriate rendering and displaying. When CVO is succesfully negotiated it shall be signalled
  13. by the MTSI client. The signalling of the CVO uses RTP Header Extensions as specified in IETF RFC 5285 [95]. The
  14. one-byte form of the header should be used. CVO information for a 2 bit granularity of Rotation (corresponding to
  15. urn:3gpp:video-orientation) is carried as a byte formatted as follows:
  16. 0 1
  17. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
  18. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  19. | ID | len=0 |0 0 0 0 C F R R|
  20. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  21. Bit# 7 6 5 4 3 2 1 0(LSB)
  22. Definition 0 0 0 0 C F R1 R0
  23. With the following definitions:
  24. C = Camera: indicates the direction of the camera used for this video stream. It can be used by the MTSI client in
  25. receiver to e.g. display the received video differently depending on the source camera.
  26. 0: Front-facing camera, facing the user. If camera direction is unknown by the sending MTSI client in the terminal then this is the default value used.
  27. 1: Back-facing camera, facing away from the user.
  28. F = Flip: indicates a horizontal (left-right flip) mirror operation on the video as sent on the link.
  29. 0: No flip operation. If the sending MTSI client in terminal does not know if a horizontal mirror operation is necessary, then this is the default value used.
  30. 1: Horizontal flip operation
  31. R1, R0 = Rotation: indicates the rotation of the video as transmitted on the link. The receiver should rotate the video to
  32. compensate that rotation. E.g. a 90 Counter Clockwise rotation should be compensated by the receiver with a 90
  33. Clockwise rotation prior to displaying.
  34. Table 7.2: Rotation signalling for 2 bit granularity
  35. R1 R0 Rotation of the video as sent on the link Rotation on the receiver before display
  36. 0 0 0 rotation None
  37. 0 1 90 Counter Clockwise (CCW) rotation or 90 CW rotation
  38. 270 Clockwise (CW) rotation
  39. 1 0 180 CCW rotation or 180 CW rotation 180 CW rotation
  40. 1 1 270 CCW rotation or 90 CW rotation 90 CCW rotation
  41. CVO information for a higher granularity of Rotation (corresponding to urn:3GPP:video-orientation:6) is carried as a
  42. byte formatted as follows:
  43. Bit# 7 6 5 4 3 2 1 0(LSB)
  44. Definition R5 R4 R3 R2 C F R1 R0
  45. where C and F are as defined above and the bits R5,R4,R3,R2,R1,R0 represent the Rotation, which indicates the
  46. rotation of the video as transmitted on the link. Table 7.3 describes the rotation to be applied by the receiver based on
  47. the rotation bits.
  48. Table 7.3: Rotation signalling for 6 bit granularity
  49. R1 R0 R5 R4 R3 R2 Rotation of the video as Rotation on the receiver
  50. sent on the link before display
  51. 0 0 0 0 0 0 0 rotation None
  52. 0 0 0 0 0 1 (360/64) Counter Clockwise (360/64) CW rotation
  53. (CCW) rotation
  54. 0 0 0 0 1 0 (2*360/64) CCW rotation (2*360/64) CW rotation
  55. . . . . . . . .
  56. . . . . . . . .
  57. . . . . . . . .
  58. 1 1 1 1 1 0 (62*360/64) CCW rotation (2*360/64) CCW rotation
  59. 1 1 1 1 1 1 (63*360/64) CCW rotation (360/64) CCW rotation
  60. */
  61. int rtp_ext_video_orientation_parse(const uint8_t* data, int bytes, struct rtp_ext_video_orientation_t *ext)
  62. {
  63. assert(1 == bytes);
  64. if (bytes < 1)
  65. return -1;
  66. ext->camera = (data[0] >> 3) & 0x01;
  67. ext->flip = (data[0] >> 2) & 0x01;
  68. ext->rotaion = (data[0] & 0x03) * 90;
  69. return 0;
  70. }
  71. int rtp_ext_video_orientation_write(uint8_t* data, int bytes, const struct rtp_ext_video_orientation_t* ext)
  72. {
  73. if (bytes < 1)
  74. return -1;
  75. data[0] = ext->camera ? 0x04 : 0;
  76. data[0] |= ext->flip ? 0x03 : 0;
  77. data[0] |= (ext->rotaion / 90) & 0x03;
  78. return 1;
  79. }