31 struct video_out_desc;
110 static struct bitbuf bitbuf_init(const uint8_t *base,
int bitsize,
int start_ofs)
119 static int bitbuf_left(
struct bitbuf *b)
121 return b->bitsize - b->ofs;
124 static uint32_t getbits(
struct bitbuf *b,
int n)
134 if (n + b->ofs > b->bitsize) {
136 n = b->bitsize - b->ofs;
138 ofs = 7 - b->ofs % 8;
140 d = b->base + b->ofs / 8;
141 for (i=0 ; i < n; i++) {
142 retval += retval + (*d & mask ? 1 : 0);
153 static void check_h261(
struct fbuf_t *b)
155 struct bitbuf
a = bitbuf_init(b->
data, b->
used * 8, 0);
172 (y & 0x4) ?
"" :
"Q",
174 while ( (x = getbits(&a, 1)) == 1)
177 while ( (x = bitbuf_left(&a)) > 0) {
190 while ( (x = getbits(&a, 1)) == 1)
192 while ( (x = bitbuf_left(&a)) > 0) {
198 void dump_buf(
struct fbuf_t *b);
199 void dump_buf(
struct fbuf_t *b)
201 int i, x, last2lines;
204 last2lines = (b->
used - 16) & ~0xf;
206 for (i = 0; i < b->
used; i++) {
211 memset(buf,
'\0',
sizeof(buf));
212 sprintf(buf,
"%04x: ", (
unsigned)i);
214 sprintf(buf + 6 + x*3,
"%02hhx ", b->
data[i]);
215 if (i > 31 && i < last2lines)
239 f, data, len, format);
246 memcpy(data+head, start, len);
280 int need = len + FF_INPUT_BUFFER_PADDING_SIZE;
289 }
else if (b->
used + need > b->
size) {
307 mask = (1 << b->
ebit) - 1;
310 dst[-1] |= (*src & mask);
318 memcpy(dst, src, len);
346 enc_ctx->flags |=CODEC_FLAG_H263P_UMV;
347 enc_ctx->flags |=CODEC_FLAG_AC_PRED;
348 enc_ctx->flags |=CODEC_FLAG_H263P_SLICE_STRUCT;
349 enc_ctx->flags |= CODEC_FLAG_H263P_AIC;
364 uint8_t *d = b->
data;
368 for (;len > 0; len -= l, d += l) {
373 if (len >= 3 && d[0] == 0 && d[1] == 0 && d[2] >= 0x80) {
375 for (i = 3; i < len - 3; i++) {
376 if (d[i] == 0 && d[i+1] == 0 && d[i+2] >= 0x80) {
382 if (l > mtu || l > len) {
385 if (l < 1 || l > mtu) {
390 if (d[0] == 0 && d[1] == 0) {
404 data[0] = data[1] = 0;
441 PLEN = ( (data[0] & 1) << 5 ) | ( (data[1] & 0xf8) >> 3);
448 data[0] = data[1] = 0;
463 struct fbuf_t *b = &v->enc_out;
466 b->
used = avcodec_encode_video(v->enc_ctx, b->
data, b->
size, v->enc_in_frame);
484 uint8_t *src = b->
data;
485 int srclen = b->
used;
493 int len = av_parser_parse(v->
parser, v->
dec_ctx, &data, &datalen, src, srclen, 0, 0);
500 if (data ==
NULL || datalen == 0)
502 ret = avcodec_decode_video(v->
dec_ctx, v->
d_frame, &full_frame, data, datalen);
511 memmove(b->
data, src, srclen);
519 .format = AST_FORMAT_H263_PLUS,
533 enc_ctx->flags |= CODEC_FLAG_H263P_UMV;
534 enc_ctx->flags |= CODEC_FLAG_H263P_AIC;
535 enc_ctx->flags |= CODEC_FLAG_H263P_SLICE_STRUCT;
536 enc_ctx->flags |= CODEC_FLAG_AC_PRED;
578 uint8_t *d = b->
data;
579 int start = 0, i,
len = b->
used;
581 const int pheader_len = 4;
582 uint8_t h263_hdr[12];
583 uint8_t *h = h263_hdr;
585 #define H263_MIN_LEN 6 589 memset(h263_hdr,
'\0',
sizeof(h263_hdr));
602 h[1] = ( (d[4] & 0x1f) << 3 ) |
603 ( (d[5] & 0xc0) >> 5 );
611 for (; i <
len ; i++) {
612 uint8_t x, rpos, lpos;
626 for (rpos = 0x80, rpos_i = 8; rpos; rpos >>= 1, rpos_i--)
630 for (lpos = rpos; lpos ; lpos >>= 1)
678 if ( (data[0] & 0x80) == 0) {
708 enc_ctx->rtp_payload_size = 0;
732 uint8_t *d = b->
data;
733 int start = 0, i,
len = b->
used;
735 const int pheader_len = 4;
737 uint8_t *h = h261_hdr;
738 int sbit = 0, ebit = 0;
740 #define H261_MIN_LEN 10 744 memset(h261_hdr,
'\0',
sizeof(h261_hdr));
751 for (i =
H261_MIN_LEN, start = 0; start < len - 1; start = i, i += 4) {
755 int found = 0, found_ebit = 0;
756 for (; i <
len ; i++) {
757 uint8_t x, rpos, lpos;
768 for (rpos = 0x80, ebit = 7; rpos; ebit--, rpos >>= 1)
772 for (lpos = (rpos >> 1); lpos ; lpos >>= 1)
790 if (i - start > mtu && found) {
807 h[0] = ( (sbit & 7) << 5 ) | ( (ebit & 7) << 2 ) | 1;
811 sbit = (8 - ebit) & 7;
835 sbit = (data[0] >> 5) & 7;
836 ebit = (data[0] >> 2) & 7;
858 enc_ctx->flags |= CODEC_FLAG_AC_PRED;
859 enc_ctx->flags |= CODEC_FLAG_H263P_UMV;
860 enc_ctx->flags |= CODEC_FLAG_QPEL;
861 enc_ctx->flags |= CODEC_FLAG_4MV;
862 enc_ctx->flags |= CODEC_FLAG_GMC;
863 enc_ctx->flags |= CODEC_FLAG_LOOP_FILTER;
864 enc_ctx->flags |= CODEC_FLAG_H263P_SLICE_STRUCT;
866 enc_ctx->rtp_payload_size = 0;
875 uint8_t *d = b->
data;
879 for (;d <
end; d +=
len, cur = f) {
880 len =
MIN(mtu, end - d);
901 int ret = avcodec_decode_video(v->
dec_ctx, v->
d_frame, &full_frame,
917 .format = AST_FORMAT_MP4_VIDEO,
928 enc_ctx->flags |= CODEC_FLAG_TRUNCATED;
932 enc_ctx->rtp_mode = 0;
933 enc_ctx->rtp_payload_size = 0;
934 enc_ctx->bit_rate_tolerance = enc_ctx->bit_rate;
940 dec_ctx->flags |= CODEC_FLAG_TRUNCATED;
963 uint8_t *
d, *start = b->
data;
964 uint8_t *
end = start + b->
used;
969 #define HAVE_NAL(x) (x[-4] == 0 && x[-3] == 0 && x[-2] == 0 && x[-1] == 1) 970 for (start += 4; start <
end; start++) {
971 int ty = start[0] & 0x1f;
972 if (
HAVE_NAL(start) && ty != 0 && ty != 31)
980 for (;start < end - 4; start =
d) {
986 for (d = start + 4; d <
end; d++) {
994 }
else if (ty == 0 || ty == 31) {
996 ty, d - (uint8_t *)b->
data, b->
used);
1000 size = d - start - 4;
1015 hdr[0] = (*start & 0xe0) | 28;
1016 hdr[1] = (*start++ & 0x1f) | 0x80 ;
1020 int frag_size =
MIN(size, mtu);
1030 data[1] = hdr[1] | (size == 0 ? 0x40 : 0);
1049 uint8_t scp[] = { 0x00, 0x00, 0x00, 0x01 };
1058 if (data[0] & 0x80) {
1064 type = data[0] & 0x1f;
1078 if (data[1] & 0x80) {
1080 data[1] |= (data[0] & 0xe0);
1091 retval =
fbuf_append(b, data + ofs, len - ofs, 0, 0);
1116 enum { CM_RD = 1, CM_WR = 2, CM_RDWR = 3 } rw;
1121 { AST_FORMAT_H263_PLUS, CODEC_ID_H263,
CM_RD },
1122 { AST_FORMAT_H263_PLUS, CODEC_ID_H263P,
CM_WR },
1127 { AST_FORMAT_MP4_VIDEO, CODEC_ID_MPEG4, CM_RDWR },
1137 for (i = video_formats; i->
ast_format != 0; i++)
1141 return CODEC_ID_NONE;
1162 for (i = 0; supported_codecs[i]; i++)
1163 if (fmt == supported_codecs[i]->
format) {
1165 supported_codecs[i]->
name, fmt);
1166 return supported_codecs[i];
1179 av_parser_close(v->
parser);
1221 v->
codec = avcodec_find_decoder(codec);
1229 v->
dec_ctx = avcodec_alloc_context();
1242 v->
parser = av_parser_init(codec);
1248 v->
d_frame = avcodec_alloc_frame();
static int mpeg4_enc_init(AVCodecContext *enc_ctx)
Asterisk main include file. File version handling, generic pbx functions.
#define ast_realloc(p, len)
A wrapper for realloc()
static int ffmpeg_encode(struct video_out_desc *v)
void fbuf_free(struct fbuf_t *)
struct fbuf_t dec_in[N_DEC_IN]
static struct ast_frame * h261_encap(struct fbuf_t *b, int mtu, struct ast_frame **tail)
static struct video_codec_desc h263p_codec
struct video_codec_desc * d_callbacks
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
static int h264_enc_init(AVCodecContext *enc_ctx)
static struct ast_frame * create_video_frame(uint8_t *start, uint8_t *end, int format, int head, struct ast_frame *prev)
struct ast_frame *(* encoder_encap_f)(struct fbuf_t *, int mtu, struct ast_frame **tail)
encapsulate the bistream in RTP frames
int(* decoder_decode_f)(struct video_dec_desc *v, struct fbuf_t *b)
actually call the decoder
int(* decoder_decap_f)(struct fbuf_t *b, uint8_t *data, int len)
extract the bitstream from RTP frames and store in the fbuf. return 0 if ok, 1 on error ...
static int fbuf_append(struct fbuf_t *b, uint8_t *src, int len, int sbit, int ebit)
struct ast_frame_subclass subclass
AVCodecParserContext * parser
static enum CodecID map_video_format(uint32_t ast_format, int rw)
map an asterisk format into an ffmpeg one
static int h263_decap(struct fbuf_t *b, uint8_t *data, int len)
static int h264_dec_init(AVCodecContext *dec_ctx)
Asterisk internal frame definitions.
struct fbuf_t * dec_in_dpy
static struct ast_frame * h263_encap(struct fbuf_t *b, int mtu, struct ast_frame **tail)
int(* decoder_init_f)(AVCodecContext *enc_ctx)
inizialize the decoder
struct fbuf_t * dec_in_cur
static struct video_codec_desc * map_video_codec(int fmt)
static int ffmpeg_decode(struct video_dec_desc *v, struct fbuf_t *b)
static struct ast_frame * h264_encap(struct fbuf_t *b, int mtu, struct ast_frame **tail)
static const struct _cm video_formats[]
static struct ast_frame * mpeg4_encap(struct fbuf_t *b, int mtu, struct ast_frame **tail)
static int h263p_enc_init(AVCodecContext *enc_ctx)
initialization of h263p
int(* encoder_init_f)(AVCodecContext *v)
initialize the encoder
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
struct sla_ringing_trunk * first
static struct video_codec_desc h264_codec
encoder_encap_f enc_encap
#define ast_calloc(num, len)
A wrapper for calloc()
static struct video_dec_desc * dec_uninit(struct video_dec_desc *v)
uninitialize the descriptor for remote video stream
static int h263p_decap(struct fbuf_t *b, uint8_t *data, int len)
extract the bitstreem from the RTP payload. This is format dependent. For h263+, the format is define...
static int h261_enc_init(AVCodecContext *enc_ctx)
static int mpeg4_decode(struct video_dec_desc *v, struct fbuf_t *b)
static int h261_decap(struct fbuf_t *b, uint8_t *data, int len)
int(* encoder_encode_f)(struct video_out_desc *v)
actually call the encoder
Data structure associated with a single frame of data.
static struct video_codec_desc h261_codec
static struct video_codec_desc h263_codec
union ast_frame::@263 data
enum ast_frame_type frametype
static int mpeg4_decap(struct fbuf_t *b, uint8_t *data, int len)
static const struct video_codec_desc * supported_codecs[]
static int h263_enc_init(AVCodecContext *enc_ctx)
decoder_decap_f dec_decap
static struct ast_frame * h263p_encap(struct fbuf_t *b, int mtu, struct ast_frame **tail)
static struct video_codec_desc mpeg4_codec
static int h264_decap(struct fbuf_t *b, uint8_t *data, int len)