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.

122 lines
3.6KB

  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. static av_cold int avui_decode_init(AVCodecContext *avctx)
  24. {
  25. avctx->pix_fmt = PIX_FMT_YUVA422P;
  26. avctx->coded_frame = avcodec_alloc_frame();
  27. if (!avctx->coded_frame) {
  28. av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
  29. return AVERROR(ENOMEM);
  30. }
  31. return 0;
  32. }
  33. static int avui_decode_frame(AVCodecContext *avctx, void *data,
  34. int *data_size, AVPacket *avpkt)
  35. {
  36. AVFrame *pic = avctx->coded_frame;
  37. const uint8_t *src = avpkt->data;
  38. const uint8_t *srca = src + 2 * (avctx->height + 16) * avctx->width + 9;
  39. uint8_t *y, *u, *v, *a;
  40. int transparent = 0, i, j, k;
  41. if (pic->data[0])
  42. avctx->release_buffer(avctx, pic);
  43. if (avpkt->size < 2 * avctx->width * (avctx->height + 16) + 4) {
  44. av_log(avctx, AV_LOG_ERROR, "Insufficient input data.\n");
  45. return AVERROR(EINVAL);
  46. }
  47. if (avpkt->size >= 4 * avctx->width * (avctx->height + 16) + 13)
  48. transparent = 1;
  49. pic->reference = 0;
  50. if (avctx->get_buffer(avctx, pic) < 0) {
  51. av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n");
  52. return AVERROR(ENOMEM);
  53. }
  54. pic->key_frame = 1;
  55. pic->pict_type = AV_PICTURE_TYPE_I;
  56. for (i = 0; i < 2; i++) {
  57. src += avctx->width * 16;
  58. srca += avctx->width * 16;
  59. y = pic->data[0] + i * pic->linesize[0];
  60. u = pic->data[1] + i * pic->linesize[1];
  61. v = pic->data[2] + i * pic->linesize[2];
  62. a = pic->data[3] + i * pic->linesize[3];
  63. for (j = 0; j < (avctx->height + 1) >> 1; j++) {
  64. for (k = 0; k < (avctx->width + 1) >> 1; k++) {
  65. u[ k ] = *src++;
  66. y[2 * k ] = *src++;
  67. a[2 * k ] = 0xFF - (transparent ? *srca++ : 0);
  68. srca++;
  69. v[ k ] = *src++;
  70. y[2 * k + 1] = *src++;
  71. a[2 * k + 1] = 0xFF - (transparent ? *srca++ : 0);
  72. srca++;
  73. }
  74. y += 2 * pic->linesize[0];
  75. u += 2 * pic->linesize[1];
  76. v += 2 * pic->linesize[2];
  77. a += 2 * pic->linesize[3];
  78. }
  79. src += 4;
  80. srca += 4;
  81. }
  82. *data_size = sizeof(AVFrame);
  83. *(AVFrame *)data = *pic;
  84. return avpkt->size;
  85. }
  86. static av_cold int avui_decode_close(AVCodecContext *avctx)
  87. {
  88. if (avctx->coded_frame->data[0])
  89. avctx->release_buffer(avctx, avctx->coded_frame);
  90. av_freep(&avctx->coded_frame);
  91. return 0;
  92. }
  93. AVCodec ff_avui_decoder = {
  94. .name = "avui",
  95. .type = AVMEDIA_TYPE_VIDEO,
  96. .id = CODEC_ID_AVUI,
  97. .init = avui_decode_init,
  98. .decode = avui_decode_frame,
  99. .close = avui_decode_close,
  100. .capabilities = CODEC_CAP_DR1,
  101. .long_name = NULL_IF_CONFIG_SMALL("AVID Meridien"),
  102. };