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.

129 lines
3.7KB

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