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.

132 lines
3.5KB

  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 "flv.h"
  21. void ff_flv2_decode_ac_esc(GetBitContext *gb, int *level, int *run, int *last){
  22. int is11 = get_bits1(gb);
  23. *last = get_bits1(gb);
  24. *run = get_bits(gb, 6);
  25. if(is11){
  26. *level = get_sbits(gb, 11);
  27. } else {
  28. *level = get_sbits(gb, 7);
  29. }
  30. }
  31. int ff_flv_decode_picture_header(MpegEncContext *s)
  32. {
  33. int format, width, height;
  34. /* picture header */
  35. if (get_bits_long(&s->gb, 17) != 1) {
  36. av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
  37. return -1;
  38. }
  39. format = get_bits(&s->gb, 5);
  40. if (format != 0 && format != 1) {
  41. av_log(s->avctx, AV_LOG_ERROR, "Bad picture format\n");
  42. return -1;
  43. }
  44. s->h263_flv = format+1;
  45. s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
  46. format = get_bits(&s->gb, 3);
  47. switch (format) {
  48. case 0:
  49. width = get_bits(&s->gb, 8);
  50. height = get_bits(&s->gb, 8);
  51. break;
  52. case 1:
  53. width = get_bits(&s->gb, 16);
  54. height = get_bits(&s->gb, 16);
  55. break;
  56. case 2:
  57. width = 352;
  58. height = 288;
  59. break;
  60. case 3:
  61. width = 176;
  62. height = 144;
  63. break;
  64. case 4:
  65. width = 128;
  66. height = 96;
  67. break;
  68. case 5:
  69. width = 320;
  70. height = 240;
  71. break;
  72. case 6:
  73. width = 160;
  74. height = 120;
  75. break;
  76. default:
  77. width = height = 0;
  78. break;
  79. }
  80. if(avcodec_check_dimensions(s->avctx, width, height))
  81. return -1;
  82. s->width = width;
  83. s->height = height;
  84. s->pict_type = FF_I_TYPE + get_bits(&s->gb, 2);
  85. s->dropable= s->pict_type > FF_P_TYPE;
  86. if (s->dropable)
  87. s->pict_type = FF_P_TYPE;
  88. skip_bits1(&s->gb); /* deblocking flag */
  89. s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
  90. s->h263_plus = 0;
  91. s->unrestricted_mv = 1;
  92. s->h263_long_vectors = 0;
  93. /* PEI */
  94. while (get_bits1(&s->gb) != 0) {
  95. skip_bits(&s->gb, 8);
  96. }
  97. s->f_code = 1;
  98. if(s->avctx->debug & FF_DEBUG_PICT_INFO){
  99. av_log(s->avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n",
  100. s->dropable ? 'D' : av_get_pict_type_char(s->pict_type), s->h263_flv-1, s->qscale, s->picture_number);
  101. }
  102. s->y_dc_scale_table=
  103. s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
  104. return 0;
  105. }
  106. AVCodec flv_decoder = {
  107. "flv",
  108. CODEC_TYPE_VIDEO,
  109. CODEC_ID_FLV1,
  110. sizeof(MpegEncContext),
  111. ff_h263_decode_init,
  112. NULL,
  113. ff_h263_decode_end,
  114. ff_h263_decode_frame,
  115. CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
  116. .long_name= NULL_IF_CONFIG_SMALL("Flash Video (FLV) / Sorenson Spark / Sorenson H.263"),
  117. .pix_fmts= ff_pixfmt_list_420,
  118. };