use a dynamic ByteIOContext instead of using the lavf buffer
this makes the code work with big packets, it is also simpler and saves a byte or 2 Originally committed as revision 10015 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
@@ -80,8 +80,8 @@ typedef struct {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
AVFormatContext *avf;
|
AVFormatContext *avf;
|
||||||
int written_packet_size;
|
// int written_packet_size;
|
||||||
int64_t packet_start;
|
// int64_t packet_start;
|
||||||
FrameCode frame_code[256];
|
FrameCode frame_code[256];
|
||||||
uint64_t next_startcode; ///< stores the next startcode if it has already been parsed but the stream is not seekable
|
uint64_t next_startcode; ///< stores the next startcode if it has already been parsed but the stream is not seekable
|
||||||
StreamContext *stream;
|
StreamContext *stream;
|
||||||
|
@@ -177,50 +177,18 @@ static inline void put_s_trace(ByteIOContext *bc, int64_t v, char *file, char *f
|
|||||||
#define put_s(bc, v) put_s_trace(bc, v, __FILE__, __PRETTY_FUNCTION__, __LINE__)
|
#define put_s(bc, v) put_s_trace(bc, v, __FILE__, __PRETTY_FUNCTION__, __LINE__)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int put_packetheader(NUTContext *nut, ByteIOContext *bc, int max_size, int calculate_checksum){
|
static void put_packet(NUTContext *nut, ByteIOContext *bc, ByteIOContext *dyn_bc, int calculate_checksum){
|
||||||
put_flush_packet(bc);
|
uint8_t *dyn_buf=NULL;
|
||||||
nut->packet_start= url_ftell(bc) - 8;
|
int dyn_size= url_close_dyn_buf(dyn_bc, &dyn_buf);
|
||||||
nut->written_packet_size = max_size;
|
|
||||||
|
|
||||||
/* packet header */
|
|
||||||
put_v(bc, nut->written_packet_size); /* forward ptr */
|
|
||||||
|
|
||||||
|
put_v(bc, dyn_size + 4*calculate_checksum);
|
||||||
if(calculate_checksum)
|
if(calculate_checksum)
|
||||||
init_checksum(bc, av_crc04C11DB7_update, 0);
|
init_checksum(bc, av_crc04C11DB7_update, 0);
|
||||||
|
put_buffer(bc, dyn_buf, dyn_size);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* must not be called more then once per packet
|
|
||||||
*/
|
|
||||||
static int update_packetheader(NUTContext *nut, ByteIOContext *bc, int additional_size, int calculate_checksum){
|
|
||||||
int64_t start= nut->packet_start;
|
|
||||||
int64_t cur= url_ftell(bc);
|
|
||||||
int size= cur - start - get_length(nut->written_packet_size) - 8;
|
|
||||||
|
|
||||||
if(calculate_checksum)
|
|
||||||
size += 4;
|
|
||||||
|
|
||||||
if(size != nut->written_packet_size){
|
|
||||||
int i;
|
|
||||||
|
|
||||||
assert( size <= nut->written_packet_size );
|
|
||||||
|
|
||||||
url_fseek(bc, start + 8, SEEK_SET);
|
|
||||||
for(i=get_length(size); i < get_length(nut->written_packet_size); i++)
|
|
||||||
put_byte(bc, 128);
|
|
||||||
put_v(bc, size);
|
|
||||||
|
|
||||||
url_fseek(bc, cur, SEEK_SET);
|
|
||||||
nut->written_packet_size= size; //FIXME may fail if multiple updates with differing sizes, as get_length may differ
|
|
||||||
|
|
||||||
if(calculate_checksum)
|
if(calculate_checksum)
|
||||||
put_le32(bc, get_checksum(bc));
|
put_le32(bc, get_checksum(bc));
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
av_free(dyn_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void write_mainheader(NUTContext *nut, ByteIOContext *bc){
|
static void write_mainheader(NUTContext *nut, ByteIOContext *bc){
|
||||||
@@ -325,7 +293,7 @@ static int write_streamheader(NUTContext *nut, ByteIOContext *bc, AVCodecContext
|
|||||||
|
|
||||||
static int write_header(AVFormatContext *s){
|
static int write_header(AVFormatContext *s){
|
||||||
NUTContext *nut = s->priv_data;
|
NUTContext *nut = s->priv_data;
|
||||||
ByteIOContext *bc = &s->pb;
|
ByteIOContext *bc = &s->pb, dyn_bc;
|
||||||
AVCodecContext *codec;
|
AVCodecContext *codec;
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
@@ -367,17 +335,17 @@ static int write_header(AVFormatContext *s){
|
|||||||
|
|
||||||
/* main header */
|
/* main header */
|
||||||
put_be64(bc, MAIN_STARTCODE);
|
put_be64(bc, MAIN_STARTCODE);
|
||||||
put_packetheader(nut, bc, 120+5*256/*FIXME check*/, 1);
|
url_open_dyn_buf(&dyn_bc);
|
||||||
write_mainheader(nut, bc);
|
write_mainheader(nut, &dyn_bc);
|
||||||
update_packetheader(nut, bc, 0, 1);
|
put_packet(nut, bc, &dyn_bc, 1);
|
||||||
|
|
||||||
for (i=0; i < s->nb_streams; i++){
|
for (i=0; i < s->nb_streams; i++){
|
||||||
codec = s->streams[i]->codec;
|
codec = s->streams[i]->codec;
|
||||||
|
|
||||||
put_be64(bc, STREAM_STARTCODE);
|
put_be64(bc, STREAM_STARTCODE);
|
||||||
put_packetheader(nut, bc, 120/*FIXME check*/ + codec->extradata_size, 1);
|
url_open_dyn_buf(&dyn_bc);
|
||||||
write_streamheader(nut, bc, codec, i);
|
write_streamheader(nut, &dyn_bc, codec, i);
|
||||||
update_packetheader(nut, bc, 0, 1);
|
put_packet(nut, bc, &dyn_bc, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
put_flush_packet(bc);
|
put_flush_packet(bc);
|
||||||
|
Reference in New Issue
Block a user