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.

130 lines
3.8KB

  1. /*
  2. * FLV decoding.
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "libavutil/imgutils.h"
  21. #include "flv.h"
  22. #include "h263.h"
  23. #include "mpegvideo.h"
  24. #include "mpegvideodata.h"
  25. int ff_flv_decode_picture_header(MpegEncContext *s)
  26. {
  27. int format, width, height;
  28. /* picture header */
  29. if (get_bits_long(&s->gb, 17) != 1) {
  30. av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
  31. return AVERROR_INVALIDDATA;
  32. }
  33. format = get_bits(&s->gb, 5);
  34. if (format != 0 && format != 1) {
  35. av_log(s->avctx, AV_LOG_ERROR, "Bad picture format\n");
  36. return AVERROR_INVALIDDATA;
  37. }
  38. s->h263_flv = format + 1;
  39. s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
  40. format = get_bits(&s->gb, 3);
  41. switch (format) {
  42. case 0:
  43. width = get_bits(&s->gb, 8);
  44. height = get_bits(&s->gb, 8);
  45. break;
  46. case 1:
  47. width = get_bits(&s->gb, 16);
  48. height = get_bits(&s->gb, 16);
  49. break;
  50. case 2:
  51. width = 352;
  52. height = 288;
  53. break;
  54. case 3:
  55. width = 176;
  56. height = 144;
  57. break;
  58. case 4:
  59. width = 128;
  60. height = 96;
  61. break;
  62. case 5:
  63. width = 320;
  64. height = 240;
  65. break;
  66. case 6:
  67. width = 160;
  68. height = 120;
  69. break;
  70. default:
  71. width = height = 0;
  72. break;
  73. }
  74. if (av_image_check_size(width, height, 0, s->avctx))
  75. return AVERROR(EINVAL);
  76. s->width = width;
  77. s->height = height;
  78. s->pict_type = AV_PICTURE_TYPE_I + get_bits(&s->gb, 2);
  79. s->droppable = s->pict_type > AV_PICTURE_TYPE_P;
  80. if (s->droppable)
  81. s->pict_type = AV_PICTURE_TYPE_P;
  82. skip_bits1(&s->gb); /* deblocking flag */
  83. s->chroma_qscale = s->qscale = get_bits(&s->gb, 5);
  84. s->h263_plus = 0;
  85. s->unrestricted_mv = 1;
  86. s->h263_long_vectors = 0;
  87. /* PEI */
  88. if (skip_1stop_8data_bits(&s->gb) < 0)
  89. return AVERROR_INVALIDDATA;
  90. s->f_code = 1;
  91. if (s->ehc_mode)
  92. s->avctx->sample_aspect_ratio= (AVRational){1,2};
  93. if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
  94. av_log(s->avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n",
  95. s->droppable ? 'D' : av_get_picture_type_char(s->pict_type),
  96. s->h263_flv - 1, s->qscale, s->picture_number);
  97. }
  98. s->y_dc_scale_table = s->c_dc_scale_table = ff_mpeg1_dc_scale_table;
  99. return 0;
  100. }
  101. AVCodec ff_flv_decoder = {
  102. .name = "flv",
  103. .long_name = NULL_IF_CONFIG_SMALL("FLV / Sorenson Spark / Sorenson H.263 (Flash Video)"),
  104. .type = AVMEDIA_TYPE_VIDEO,
  105. .id = AV_CODEC_ID_FLV1,
  106. .priv_data_size = sizeof(MpegEncContext),
  107. .init = ff_h263_decode_init,
  108. .close = ff_h263_decode_end,
  109. .decode = ff_h263_decode_frame,
  110. .capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1,
  111. .max_lowres = 3,
  112. .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
  113. AV_PIX_FMT_NONE },
  114. };