changeset 4097:f8a743bd2df8 libavformat

Split RMContext into RMDemux/MuxContext and make them private in rmdec/enc.c. Reason for this is that there are no shared entries in the demuxer/muxer context, making it a mystery as to why it was shared between the two. See "[PATCH] clean rmdemux/muxcontext" patch on mailinglist.
author rbultje
date Sat, 13 Dec 2008 21:40:20 +0000
parents 233ba738a68e
children 10d52cda08dd
files rm.h rmdec.c rmenc.c
diffstat 3 files changed, 59 insertions(+), 58 deletions(-) [+]
line wrap: on
line diff
--- a/rm.h	Sat Dec 13 21:37:27 2008 +0000
+++ b/rm.h	Sat Dec 13 21:40:20 2008 +0000
@@ -24,45 +24,6 @@
 
 #include "avformat.h"
 
-
-typedef struct {
-    int nb_packets;
-    int packet_total_size;
-    int packet_max_size;
-    /* codec related output */
-    int bit_rate;
-    float frame_rate;
-    int nb_frames;    /* current frame number */
-    int total_frames; /* total number of frames */
-    int num;
-    AVCodecContext *enc;
-} StreamInfo;
-
-typedef struct {
-    StreamInfo streams[2];
-    StreamInfo *audio_stream, *video_stream;
-    int data_pos; /* position of the data after the header */
-    int nb_packets;
-    int old_format;
-    int current_stream;
-    int remaining_len;
-    uint8_t *videobuf; ///< place to store merged video frame
-    int videobufsize;  ///< current assembled frame size
-    int videobufpos;   ///< position for the next slice in the video buffer
-    int curpic_num;    ///< picture number of current frame
-    int cur_slice, slices;
-    int64_t pktpos;    ///< first slice position in file
-    /// Audio descrambling matrix parameters
-    uint8_t *audiobuf; ///< place to store reordered audio data
-    int64_t audiotimestamp; ///< Audio packet timestamp
-    int sub_packet_cnt; // Subpacket counter, used while reading
-    int sub_packet_size, sub_packet_h, coded_framesize; ///< Descrambling parameters from container
-    int audio_stream_num; ///< Stream number for audio packets
-    int audio_pkt_cnt; ///< Output packet counter
-    int audio_framesize; /// Audio frame size from container
-    int sub_packet_lengths[16]; /// Length of each aac subpacket
-} RMContext;
-
 /*< input format for Realmedia-style RTSP streams */
 extern AVInputFormat rdt_demuxer;
 
--- a/rmdec.c	Sat Dec 13 21:37:27 2008 +0000
+++ b/rmdec.c	Sat Dec 13 21:40:20 2008 +0000
@@ -21,7 +21,28 @@
 
 #include "libavutil/avstring.h"
 #include "avformat.h"
-#include "rm.h"
+
+typedef struct {
+    int nb_packets;
+    int old_format;
+    int current_stream;
+    int remaining_len;
+    uint8_t *videobuf; ///< place to store merged video frame
+    int videobufsize;  ///< current assembled frame size
+    int videobufpos;   ///< position for the next slice in the video buffer
+    int curpic_num;    ///< picture number of current frame
+    int cur_slice, slices;
+    int64_t pktpos;    ///< first slice position in file
+    /// Audio descrambling matrix parameters
+    uint8_t *audiobuf; ///< place to store reordered audio data
+    int64_t audiotimestamp; ///< Audio packet timestamp
+    int sub_packet_cnt; // Subpacket counter, used while reading
+    int sub_packet_size, sub_packet_h, coded_framesize; ///< Descrambling parameters from container
+    int audio_stream_num; ///< Stream number for audio packets
+    int audio_pkt_cnt; ///< Output packet counter
+    int audio_framesize; /// Audio frame size from container
+    int sub_packet_lengths[16]; /// Length of each aac subpacket
+} RMDemuxContext;
 
 static inline void get_strl(ByteIOContext *pb, char *buf, int buf_size, int len)
 {
@@ -50,7 +71,7 @@
 static int rm_read_audio_stream_info(AVFormatContext *s, ByteIOContext *pb,
                                      AVStream *st, int read_all)
 {
-    RMContext *rm = s->priv_data;
+    RMDemuxContext *rm = s->priv_data;
     char buf[256];
     uint32_t version;
     int i;
@@ -267,7 +288,7 @@
 
 static int rm_read_header_old(AVFormatContext *s, AVFormatParameters *ap)
 {
-    RMContext *rm = s->priv_data;
+    RMDemuxContext *rm = s->priv_data;
     AVStream *st;
 
     rm->old_format = 1;
@@ -279,7 +300,7 @@
 
 static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
 {
-    RMContext *rm = s->priv_data;
+    RMDemuxContext *rm = s->priv_data;
     AVStream *st;
     ByteIOContext *pb = s->pb;
     unsigned int tag;
@@ -396,7 +417,7 @@
 #define RAW_PACKET_SIZE 1000
 
 static int sync(AVFormatContext *s, int64_t *timestamp, int *flags, int *stream_index, int64_t *pos){
-    RMContext *rm = s->priv_data;
+    RMDemuxContext *rm = s->priv_data;
     ByteIOContext *pb = s->pb;
     int len, num, res, i;
     AVStream *st;
@@ -452,7 +473,7 @@
 }
 
 static int rm_assemble_video_frame(AVFormatContext *s, ByteIOContext *pb,
-                                   RMContext *rm, AVPacket *pkt, int len)
+                                   RMDemuxContext *rm, AVPacket *pkt, int len)
 {
     int hdr, seq, pic_num, len2, pos;
     int type;
@@ -553,7 +574,7 @@
                     AVStream *st, int len, AVPacket *pkt,
                     int *seq, int *flags, int64_t *timestamp)
 {
-    RMContext *rm = s->priv_data;
+    RMDemuxContext *rm = s->priv_data;
 
     if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
         rm->current_stream= st->id;
@@ -651,7 +672,7 @@
 ff_rm_retrieve_cache (AVFormatContext *s, ByteIOContext *pb,
                       AVStream *st, AVPacket *pkt)
 {
-    RMContext *rm = s->priv_data;
+    RMDemuxContext *rm = s->priv_data;
 
     assert (rm->audio_pkt_cnt > 0);
 
@@ -670,7 +691,7 @@
 
 static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
-    RMContext *rm = s->priv_data;
+    RMDemuxContext *rm = s->priv_data;
     ByteIOContext *pb = s->pb;
     AVStream *st;
     int i, len;
@@ -728,7 +749,7 @@
 
 static int rm_read_close(AVFormatContext *s)
 {
-    RMContext *rm = s->priv_data;
+    RMDemuxContext *rm = s->priv_data;
 
     av_free(rm->audiobuf);
     av_free(rm->videobuf);
@@ -751,7 +772,7 @@
 static int64_t rm_read_dts(AVFormatContext *s, int stream_index,
                                int64_t *ppos, int64_t pos_limit)
 {
-    RMContext *rm = s->priv_data;
+    RMDemuxContext *rm = s->priv_data;
     int64_t pos, dts;
     int stream_index2, flags, len, h;
 
@@ -794,7 +815,7 @@
 AVInputFormat rm_demuxer = {
     "rm",
     NULL_IF_CONFIG_SMALL("RM format"),
-    sizeof(RMContext),
+    sizeof(RMDemuxContext),
     rm_probe,
     rm_read_header,
     rm_read_packet,
@@ -806,6 +827,6 @@
 AVInputFormat rdt_demuxer = {
     "rdt",
     NULL_IF_CONFIG_SMALL("RDT demuxer"),
-    sizeof(RMContext),
+    sizeof(RMDemuxContext),
     NULL, NULL, NULL, rm_read_close, NULL, NULL
 };
--- a/rmenc.c	Sat Dec 13 21:37:27 2008 +0000
+++ b/rmenc.c	Sat Dec 13 21:40:20 2008 +0000
@@ -21,6 +21,25 @@
 #include "avformat.h"
 #include "rm.h"
 
+typedef struct {
+    int nb_packets;
+    int packet_total_size;
+    int packet_max_size;
+    /* codec related output */
+    int bit_rate;
+    float frame_rate;
+    int nb_frames;    /* current frame number */
+    int total_frames; /* total number of frames */
+    int num;
+    AVCodecContext *enc;
+} StreamInfo;
+
+typedef struct {
+    StreamInfo streams[2];
+    StreamInfo *audio_stream, *video_stream;
+    int data_pos; /* position of the data after the header */
+} RMMuxContext;
+
 /* in ms */
 #define BUFFER_DURATION 0
 
@@ -44,7 +63,7 @@
 static void rv10_write_header(AVFormatContext *ctx,
                               int data_size, int index_pos)
 {
-    RMContext *rm = ctx->priv_data;
+    RMMuxContext *rm = ctx->priv_data;
     ByteIOContext *s = ctx->pb;
     StreamInfo *stream;
     unsigned char *data_offset_ptr, *start_ptr;
@@ -271,7 +290,7 @@
 
 static int rm_write_header(AVFormatContext *s)
 {
-    RMContext *rm = s->priv_data;
+    RMMuxContext *rm = s->priv_data;
     StreamInfo *stream;
     int n;
     AVCodecContext *codec;
@@ -315,7 +334,7 @@
 static int rm_write_audio(AVFormatContext *s, const uint8_t *buf, int size, int flags)
 {
     uint8_t *buf1;
-    RMContext *rm = s->priv_data;
+    RMMuxContext *rm = s->priv_data;
     ByteIOContext *pb = s->pb;
     StreamInfo *stream = rm->audio_stream;
     int i;
@@ -339,7 +358,7 @@
 
 static int rm_write_video(AVFormatContext *s, const uint8_t *buf, int size, int flags)
 {
-    RMContext *rm = s->priv_data;
+    RMMuxContext *rm = s->priv_data;
     ByteIOContext *pb = s->pb;
     StreamInfo *stream = rm->video_stream;
     int key_frame = !!(flags & PKT_FLAG_KEY);
@@ -393,7 +412,7 @@
 
 static int rm_write_trailer(AVFormatContext *s)
 {
-    RMContext *rm = s->priv_data;
+    RMMuxContext *rm = s->priv_data;
     int data_size, index_pos, i;
     ByteIOContext *pb = s->pb;
 
@@ -435,7 +454,7 @@
     NULL_IF_CONFIG_SMALL("RM format"),
     "application/vnd.rn-realmedia",
     "rm,ra",
-    sizeof(RMContext),
+    sizeof(RMMuxContext),
     CODEC_ID_AC3,
     CODEC_ID_RV10,
     rm_write_header,