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.

135 lines
3.0KB

  1. /*
  2. * Raw DV format
  3. * Copyright (c) 2002 Fabrice Bellard.
  4. *
  5. * This library 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 of the License, or (at your option) any later version.
  9. *
  10. * This library 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 this library; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include "avformat.h"
  20. #define NTSC_FRAME_SIZE 120000
  21. #define PAL_FRAME_SIZE 144000
  22. typedef struct DVDemuxContext {
  23. int is_audio;
  24. } DVDemuxContext;
  25. /* raw input */
  26. static int dv_read_header(AVFormatContext *s,
  27. AVFormatParameters *ap)
  28. {
  29. AVStream *vst, *ast;
  30. vst = av_new_stream(s, 0);
  31. if (!vst)
  32. return AVERROR_NOMEM;
  33. vst->codec.codec_type = CODEC_TYPE_VIDEO;
  34. vst->codec.codec_id = CODEC_ID_DVVIDEO;
  35. #if 0
  36. ast = av_new_stream(s, 1);
  37. if (!ast)
  38. return AVERROR_NOMEM;
  39. ast->codec.codec_type = CODEC_TYPE_AUDIO;
  40. ast->codec.codec_id = CODEC_ID_DVAUDIO;
  41. #endif
  42. return 0;
  43. }
  44. /* XXX: build fake audio stream when DV audio decoder will be finished */
  45. static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
  46. {
  47. int ret, size, dsf;
  48. uint8_t buf[4];
  49. ret = get_buffer(&s->pb, buf, 4);
  50. if (ret <= 0)
  51. return -EIO;
  52. dsf = buf[3] & 0x80;
  53. if (!dsf)
  54. size = NTSC_FRAME_SIZE;
  55. else
  56. size = PAL_FRAME_SIZE;
  57. if (av_new_packet(pkt, size) < 0)
  58. return -EIO;
  59. pkt->stream_index = 0;
  60. memcpy(pkt->data, buf, 4);
  61. ret = get_buffer(&s->pb, pkt->data + 4, size - 4);
  62. if (ret <= 0) {
  63. av_free_packet(pkt);
  64. return -EIO;
  65. }
  66. return ret;
  67. }
  68. static int dv_read_close(AVFormatContext *s)
  69. {
  70. return 0;
  71. }
  72. static AVInputFormat dv_iformat = {
  73. "dv",
  74. "DV video format",
  75. sizeof(DVDemuxContext),
  76. NULL,
  77. dv_read_header,
  78. dv_read_packet,
  79. dv_read_close,
  80. .extensions = "dv",
  81. };
  82. #if 0
  83. int dv_write_header(struct AVFormatContext *s)
  84. {
  85. return 0;
  86. }
  87. int dv_write_packet(struct AVFormatContext *s,
  88. int stream_index,
  89. unsigned char *buf, int size, int force_pts)
  90. {
  91. put_buffer(&s->pb, buf, size);
  92. put_flush_packet(&s->pb);
  93. return 0;
  94. }
  95. int dv_write_trailer(struct AVFormatContext *s)
  96. {
  97. return 0;
  98. }
  99. AVOutputFormat dv_oformat = {
  100. "dv",
  101. "DV video format",
  102. NULL,
  103. "dv",
  104. 0,
  105. CODEC_ID_DVVIDEO,
  106. CODEC_ID_DVAUDIO,
  107. dv_write_header,
  108. dv_write_packet,
  109. dv_write_trailer,
  110. };
  111. #endif
  112. int dv_init(void)
  113. {
  114. av_register_input_format(&dv_iformat);
  115. // av_register_output_format(&dv_oformat);
  116. return 0;
  117. }