BoxVideoMessage.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* _____ _
  2. * |_ _| |_ _ _ ___ ___ _ __ __ _
  3. * | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. * |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. *
  6. * Threema Java Client
  7. * Copyright (c) 2013-2021 Threema GmbH
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. package ch.threema.client;
  22. import org.apache.commons.io.EndianUtils;
  23. import org.slf4j.Logger;
  24. import org.slf4j.LoggerFactory;
  25. import java.io.ByteArrayOutputStream;
  26. import java.io.IOException;
  27. /**
  28. * A message that has a video including thumbnail (stored on the blob server) as its content.
  29. *
  30. * The contents are referenced by the {@code videoBlobId}/{@code thumbnailBlobId},
  31. * the {@code videoSize}/{@code thumbnailSize} in bytes, and the {@code encryptionKey}
  32. * to be used when decrypting the video blob.
  33. *
  34. * The thumbnail uses the same key, the nonces are as follows:
  35. *
  36. * Video: 0x000000000000000000000000000000000000000000000001
  37. * Thumbnail: 0x000000000000000000000000000000000000000000000002
  38. */
  39. public class BoxVideoMessage extends AbstractMessage {
  40. private static final Logger logger = LoggerFactory.getLogger(BoxVideoMessage.class);
  41. private int duration;
  42. private byte[] videoBlobId;
  43. private int videoSize;
  44. private byte[] thumbnailBlobId;
  45. private int thumbnailSize;
  46. private byte[] encryptionKey;
  47. public BoxVideoMessage() {
  48. super();
  49. }
  50. @Override
  51. public int getType() {
  52. return ProtocolDefines.MSGTYPE_VIDEO;
  53. }
  54. @Override
  55. public boolean shouldPush() {
  56. return true;
  57. }
  58. @Override
  59. public byte[] getBody() {
  60. ByteArrayOutputStream bos = new ByteArrayOutputStream();
  61. try {
  62. EndianUtils.writeSwappedShort(bos, (short)duration);
  63. bos.write(videoBlobId);
  64. EndianUtils.writeSwappedInteger(bos, videoSize);
  65. bos.write(thumbnailBlobId);
  66. EndianUtils.writeSwappedInteger(bos, thumbnailSize);
  67. bos.write(encryptionKey);
  68. } catch (IOException e) {
  69. throw new RuntimeException(e);
  70. }
  71. return bos.toByteArray();
  72. }
  73. public int getDuration() {
  74. return duration;
  75. }
  76. public void setDuration(int duration) {
  77. this.duration = duration;
  78. }
  79. public byte[] getVideoBlobId() {
  80. return videoBlobId;
  81. }
  82. public void setVideoBlobId(byte[] videoBlobId) {
  83. this.videoBlobId = videoBlobId;
  84. }
  85. public int getVideoSize() {
  86. return videoSize;
  87. }
  88. public void setVideoSize(int videoSize) {
  89. this.videoSize = videoSize;
  90. }
  91. public byte[] getThumbnailBlobId() {
  92. return thumbnailBlobId;
  93. }
  94. public void setThumbnailBlobId(byte[] thumbnailBlobId) {
  95. this.thumbnailBlobId = thumbnailBlobId;
  96. }
  97. public int getThumbnailSize() {
  98. return thumbnailSize;
  99. }
  100. public void setThumbnailSize(int thumbnailSize) {
  101. this.thumbnailSize = thumbnailSize;
  102. }
  103. public byte[] getEncryptionKey() {
  104. return encryptionKey;
  105. }
  106. public void setEncryptionKey(byte[] encryptionKey) {
  107. this.encryptionKey = encryptionKey;
  108. }
  109. }