OLD | NEW |
1 /* | 1 /* |
2 * copyright (c) 2010 Google Inc. | 2 * copyright (c) 2010 Google Inc. |
3 * | 3 * |
4 * This file is part of FFmpeg. | 4 * This file is part of FFmpeg. |
5 * | 5 * |
6 * FFmpeg is free software; you can redistribute it and/or | 6 * FFmpeg is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Lesser General Public | 7 * modify it under the terms of the GNU Lesser General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2.1 of the License, or (at your option) any later version. | 9 * version 2.1 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 79 |
80 ++ctx->frames; | 80 ++ctx->frames; |
81 return 0; | 81 return 0; |
82 } | 82 } |
83 | 83 |
84 AVBitStreamFilter vc1_asftorcv_bsf = { | 84 AVBitStreamFilter vc1_asftorcv_bsf = { |
85 "vc1_asftorcv", | 85 "vc1_asftorcv", |
86 sizeof(ASFTORCVBSFContext), | 86 sizeof(ASFTORCVBSFContext), |
87 asftorcv_filter, | 87 asftorcv_filter, |
88 }; | 88 }; |
| 89 /* |
| 90 * copyright (c) 2010 Google Inc. |
| 91 * |
| 92 * This file is part of FFmpeg. |
| 93 * |
| 94 * FFmpeg is free software; you can redistribute it and/or |
| 95 * modify it under the terms of the GNU Lesser General Public |
| 96 * License as published by the Free Software Foundation; either |
| 97 * version 2.1 of the License, or (at your option) any later version. |
| 98 * |
| 99 * FFmpeg is distributed in the hope that it will be useful, |
| 100 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 101 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 102 * Lesser General Public License for more details. |
| 103 * |
| 104 * You should have received a copy of the GNU Lesser General Public |
| 105 * License along with FFmpeg; if not, write to the Free Software |
| 106 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 107 */ |
| 108 |
| 109 #include "avcodec.h" |
| 110 #include "bytestream.h" |
| 111 |
| 112 #define RCV_STREAM_HEADER_SIZE 36 |
| 113 #define RCV_PICTURE_HEADER_SIZE 8 |
| 114 |
| 115 typedef struct ASFTORCVBSFContext { |
| 116 int frames; |
| 117 } ASFTORCVBSFContext; |
| 118 |
| 119 static int asftorcv_filter(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx
, const char *args, |
| 120 uint8_t **poutbuf, int *poutbuf_size, |
| 121 const uint8_t *buf, int buf_size, int keyframe){ |
| 122 ASFTORCVBSFContext* ctx = (ASFTORCVBSFContext*)bsfc->priv_data; |
| 123 |
| 124 if (avctx->codec_id != CODEC_ID_WMV3) { |
| 125 av_log(avctx, AV_LOG_ERROR, "Only WMV3 is accepted!\n"); |
| 126 return -1; |
| 127 } |
| 128 |
| 129 uint8_t* bs = NULL; |
| 130 if (!ctx->frames) { |
| 131 // Write the header if this is the first frame. |
| 132 *poutbuf = av_malloc(RCV_STREAM_HEADER_SIZE + RCV_PICTURE_HEADER_SIZE +
buf_size); |
| 133 *poutbuf_size = RCV_STREAM_HEADER_SIZE + RCV_PICTURE_HEADER_SIZE + buf_s
ize; |
| 134 bs = *poutbuf; |
| 135 |
| 136 // The following structure of stream header comes from libavformat/vc1te
stenc.c. |
| 137 bytestream_put_le24(&bs, 0); // Frame count. 0 for streaming. |
| 138 bytestream_put_byte(&bs, 0xC5); |
| 139 bytestream_put_le32(&bs, 4); // 4 bytes of extra data. |
| 140 bytestream_put_byte(&bs, avctx->extradata[0]); |
| 141 bytestream_put_byte(&bs, avctx->extradata[1]); |
| 142 bytestream_put_byte(&bs, avctx->extradata[2]); |
| 143 bytestream_put_byte(&bs, avctx->extradata[3]); |
| 144 bytestream_put_le32(&bs, avctx->height); |
| 145 bytestream_put_le32(&bs, avctx->width); |
| 146 bytestream_put_le32(&bs, 0xC); |
| 147 bytestream_put_le24(&bs, 0); // hrd_buffer |
| 148 bytestream_put_byte(&bs, 0x80); // level|cbr|res1 |
| 149 bytestream_put_le32(&bs, 0); // hrd_rate |
| 150 |
| 151 // The following LE32 describes the frame rate. Since we don't care so f
ill |
| 152 // it with 0xFFFFFFFF which means variable framerate. |
| 153 // See: libavformat/vc1testenc.c |
| 154 bytestream_put_le32(&bs, 0xFFFFFFFF); |
| 155 } else { |
| 156 *poutbuf = av_malloc(RCV_PICTURE_HEADER_SIZE + buf_size); |
| 157 *poutbuf_size = RCV_PICTURE_HEADER_SIZE + buf_size; |
| 158 bs = *poutbuf; |
| 159 } |
| 160 |
| 161 // Write the picture header. |
| 162 bytestream_put_le32(&bs, buf_size | (keyframe ? 0x80000000 : 0)); |
| 163 |
| 164 // The following LE32 describes the pts. Since we don't care so fill it wit
h 0. |
| 165 bytestream_put_le32(&bs, 0); |
| 166 memcpy(bs, buf, buf_size); |
| 167 |
| 168 ++ctx->frames; |
| 169 return 0; |
| 170 } |
| 171 |
| 172 AVBitStreamFilter vc1_asftorcv_bsf = { |
| 173 "vc1_asftorcv", |
| 174 sizeof(ASFTORCVBSFContext), |
| 175 asftorcv_filter, |
| 176 }; |
OLD | NEW |