You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
4.2KB

  1. /*
  2. * AVID Meridien decoder
  3. *
  4. * Copyright (c) 2012 Carl Eugen Hoyos
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg 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 GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #include "avcodec.h"
  23. #include "internal.h"
  24. #include "libavutil/intreadwrite.h"
  25. static av_cold int avui_decode_init(AVCodecContext *avctx)
  26. {
  27. avctx->pix_fmt = AV_PIX_FMT_YUVA422P;
  28. return 0;
  29. }
  30. static int avui_decode_frame(AVCodecContext *avctx, void *data,
  31. int *got_frame, AVPacket *avpkt)
  32. {
  33. int ret;
  34. AVFrame *pic = data;
  35. const uint8_t *src = avpkt->data, *extradata = avctx->extradata;
  36. const uint8_t *srca;
  37. uint8_t *y, *u, *v, *a;
  38. int transparent, interlaced = 1, skip, opaque_length, i, j, k;
  39. uint32_t extradata_size = avctx->extradata_size;
  40. while (extradata_size >= 24) {
  41. uint32_t atom_size = AV_RB32(extradata);
  42. if (!memcmp(&extradata[4], "APRGAPRG0001", 12)) {
  43. interlaced = extradata[19] != 1;
  44. break;
  45. }
  46. if (atom_size && atom_size <= extradata_size) {
  47. extradata += atom_size;
  48. extradata_size -= atom_size;
  49. } else {
  50. break;
  51. }
  52. }
  53. if (avctx->height == 486) {
  54. skip = 10;
  55. } else {
  56. skip = 16;
  57. }
  58. opaque_length = 2 * avctx->width * (avctx->height + skip) + 4 * interlaced;
  59. if (avpkt->size < opaque_length) {
  60. av_log(avctx, AV_LOG_ERROR, "Insufficient input data.\n");
  61. return AVERROR(EINVAL);
  62. }
  63. transparent = avctx->bits_per_coded_sample == 32 &&
  64. avpkt->size >= opaque_length * 2 + 4;
  65. srca = src + opaque_length + 5;
  66. if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
  67. return ret;
  68. pic->key_frame = 1;
  69. pic->pict_type = AV_PICTURE_TYPE_I;
  70. if (!interlaced) {
  71. src += avctx->width * skip;
  72. srca += avctx->width * skip;
  73. }
  74. for (i = 0; i < interlaced + 1; i++) {
  75. src += avctx->width * skip;
  76. srca += avctx->width * skip;
  77. if (interlaced && avctx->height == 486) {
  78. y = pic->data[0] + (1 - i) * pic->linesize[0];
  79. u = pic->data[1] + (1 - i) * pic->linesize[1];
  80. v = pic->data[2] + (1 - i) * pic->linesize[2];
  81. a = pic->data[3] + (1 - i) * pic->linesize[3];
  82. } else {
  83. y = pic->data[0] + i * pic->linesize[0];
  84. u = pic->data[1] + i * pic->linesize[1];
  85. v = pic->data[2] + i * pic->linesize[2];
  86. a = pic->data[3] + i * pic->linesize[3];
  87. }
  88. for (j = 0; j < avctx->height >> interlaced; j++) {
  89. for (k = 0; k < avctx->width >> 1; k++) {
  90. u[ k ] = *src++;
  91. y[2 * k ] = *src++;
  92. a[2 * k ] = 0xFF - (transparent ? *srca++ : 0);
  93. srca++;
  94. v[ k ] = *src++;
  95. y[2 * k + 1] = *src++;
  96. a[2 * k + 1] = 0xFF - (transparent ? *srca++ : 0);
  97. srca++;
  98. }
  99. y += (interlaced + 1) * pic->linesize[0];
  100. u += (interlaced + 1) * pic->linesize[1];
  101. v += (interlaced + 1) * pic->linesize[2];
  102. a += (interlaced + 1) * pic->linesize[3];
  103. }
  104. src += 4;
  105. srca += 4;
  106. }
  107. *got_frame = 1;
  108. return avpkt->size;
  109. }
  110. AVCodec ff_avui_decoder = {
  111. .name = "avui",
  112. .long_name = NULL_IF_CONFIG_SMALL("Avid Meridien Uncompressed"),
  113. .type = AVMEDIA_TYPE_VIDEO,
  114. .id = AV_CODEC_ID_AVUI,
  115. .init = avui_decode_init,
  116. .decode = avui_decode_frame,
  117. .capabilities = AV_CODEC_CAP_DR1,
  118. };