[Ffmpeg-devel] [patch] cleanup: const-correctness + static

Stefan Huehner stefan
Sat Jun 17 20:34:26 CEST 2006


Hi,

attached patch add some more const to (mostly) char* and makes some
functions static, which aren't used outside its declaring source file
and which have no corresponding prototype.
Please review if any of these functions have to be available for
external projects linking to ffmpeg. Then prototype should be added in
the headers files instead of making these function private.

Regards,
Stefan
-------------- next part --------------
Index: ffmpeg.c
===================================================================
--- ffmpeg.c	(revision 5492)
+++ ffmpeg.c	(working copy)
@@ -211,12 +211,12 @@
 static int rate_emu = 0;
 
 #ifdef CONFIG_BKTR
-static char *video_grab_format = "bktr";
+static const char *video_grab_format = "bktr";
 #else
 #ifdef CONFIG_VIDEO4LINUX2
-static char *video_grab_format = "video4linux2";
+static const char *video_grab_format = "video4linux2";
 #else
-static char *video_grab_format = "video4linux";
+static const char *video_grab_format = "video4linux";
 #endif
 #endif
 static char *video_device = NULL;
@@ -224,7 +224,7 @@
 static int  video_channel = 0;
 static char *video_standard = "ntsc";
 
-static char *audio_grab_format = "audio_device";
+static const char *audio_grab_format = "audio_device";
 static char *audio_device = NULL;
 static int audio_volume = 256;
 
Index: vhook/watermark.c
===================================================================
--- vhook/watermark.c	(revision 5492)
+++ vhook/watermark.c	(working copy)
@@ -164,7 +164,7 @@
 /****************************************************************************
  * For mode 0 (the original one)
  ****************************************************************************/
-void Process0(void *ctx,
+static void Process0(void *ctx,
               AVPicture *picture,
               enum PixelFormat pix_fmt,
               int src_width,
@@ -276,7 +276,7 @@
 /****************************************************************************
  * For mode 1 (the original one)
  ****************************************************************************/
-void Process1(void *ctx,
+static void Process1(void *ctx,
               AVPicture *picture,
               enum PixelFormat pix_fmt,
               int src_width,
Index: libavcodec/truespeech.c
===================================================================
--- libavcodec/truespeech.c	(revision 5492)
+++ libavcodec/truespeech.c	(working copy)
@@ -188,7 +188,8 @@
 
 static void truespeech_apply_twopoint_filter(TSContext *dec, int quart)
 {
-    int16_t tmp[146 + 60], *ptr0, *ptr1, *filter;
+    int16_t tmp[146 + 60], *ptr0, *ptr1;
+    const int16_t *filter;
     int i, t, off;
 
     t = dec->offset2[quart];
@@ -201,7 +202,7 @@
     off = (t / 25) + dec->offset1[quart >> 1] + 18;
     ptr0 = tmp + 145 - off;
     ptr1 = tmp + 146;
-    filter = (int16_t*)ts_240 + (t % 25) * 2;
+    filter = (const int16_t*)ts_240 + (t % 25) * 2;
     for(i = 0; i < 60; i++){
         t = (ptr0[0] * filter[0] + ptr0[1] * filter[1] + 0x2000) >> 14;
         ptr0++;
@@ -214,7 +215,8 @@
 {
     int16_t tmp[7];
     int i, j, t;
-    int16_t *ptr1, *ptr2;
+    const int16_t *ptr1;
+    int16_t *ptr2;
     int coef;
 
     memset(out, 0, 60 * 2);
@@ -225,7 +227,7 @@
     }
 
     coef = dec->pulsepos[quart] >> 15;
-    ptr1 = (int16_t*)ts_140 + 30;
+    ptr1 = (const int16_t*)ts_140 + 30;
     ptr2 = tmp;
     for(i = 0, j = 3; (i < 30) && (j > 0); i++){
         t = *ptr1++;
@@ -238,7 +240,7 @@
         }
     }
     coef = dec->pulsepos[quart] & 0x7FFF;
-    ptr1 = (int16_t*)ts_140;
+    ptr1 = (const int16_t*)ts_140;
     for(i = 30, j = 4; (i < 60) && (j > 0); i++){
         t = *ptr1++;
         if(coef >= t)
Index: libavcodec/png.c
===================================================================
--- libavcodec/png.c	(revision 5492)
+++ libavcodec/png.c	(working copy)
@@ -346,7 +346,7 @@
 
     d = dst;
     for(j = 0; j < width; j++) {
-        v = ((uint32_t *)src)[j];
+        v = ((const uint32_t *)src)[j];
         d[0] = v >> 16;
         d[1] = v >> 8;
         d[2] = v;
Index: libavcodec/alac.c
===================================================================
--- libavcodec/alac.c	(revision 5492)
+++ libavcodec/alac.c	(working copy)
@@ -407,7 +407,7 @@
     }
 }
 
-void deinterlace_16(int32_t *buffer_a, int32_t *buffer_b,
+static void deinterlace_16(int32_t *buffer_a, int32_t *buffer_b,
                     int16_t *buffer_out,
                     int numchannels, int numsamples,
                     uint8_t interlacing_shift,
Index: libavcodec/resample2.c
===================================================================
--- libavcodec/resample2.c	(revision 5492)
+++ libavcodec/resample2.c	(working copy)
@@ -62,7 +62,7 @@
 /**
  * 0th order modified bessel function of the first kind.
  */
-double bessel(double x){
+static double bessel(double x){
     double v=1;
     double t=1;
     int i;
Index: libpostproc/postprocess.c
===================================================================
--- libpostproc/postprocess.c	(revision 5492)
+++ libpostproc/postprocess.c	(working copy)
@@ -161,7 +161,7 @@
         {NULL, NULL,0,0,0,0} //End Marker
 };
 
-static char *replaceTable[]=
+static const char *replaceTable[]=
 {
         "default",      "hdeblock:a,vdeblock:a,dering:a",
         "de",           "hdeblock:a,vdeblock:a,dering:a",
@@ -766,8 +766,8 @@
 {
         char temp[GET_MODE_BUFFER_SIZE];
         char *p= temp;
-        char *filterDelimiters= ",/";
-        char *optionDelimiters= ":";
+        const char *filterDelimiters= ",/";
+        const char *optionDelimiters= ":";
         struct PPMode *ppMode;
         char *filterToken;
 
Index: libpostproc/postprocess_internal.h
===================================================================
--- libpostproc/postprocess_internal.h	(revision 5492)
+++ libpostproc/postprocess_internal.h	(working copy)
@@ -79,8 +79,8 @@
  * Postprocessng filter.
  */
 struct PPFilter{
-        char *shortName;
-        char *longName;
+        const char *shortName;
+        const char *longName;
         int chromDefault;       ///< is chrominance filtering on by default if this filter is manually activated
         int minLumQuality;      ///< minimum quality to turn luminance filtering on
         int minChromQuality;    ///< minimum quality to turn chrominance filtering on
Index: ffplay.c
===================================================================
--- ffplay.c	(revision 5492)
+++ ffplay.c	(working copy)
@@ -1735,7 +1735,7 @@
     }
 }
 
-void dump_stream_info(AVFormatContext *s)
+static void dump_stream_info(const AVFormatContext *s)
 {
     if (s->track != 0)
         fprintf(stderr, "Track: %d\n", s->track);
@@ -2042,7 +2042,7 @@
     SDL_DestroyMutex(is->video_decoder_mutex);
 }
 
-void stream_cycle_channel(VideoState *is, int codec_type)
+static void stream_cycle_channel(VideoState *is, int codec_type)
 {
     AVFormatContext *ic = is->ic;
     int start_index, stream_index;
@@ -2092,7 +2092,7 @@
 }
 
 
-void toggle_full_screen(void)
+static void toggle_full_screen(void)
 {
     int w, h, flags;
     is_full_screen = !is_full_screen;
@@ -2117,14 +2117,14 @@
     }
 }
 
-void toggle_pause(void)
+static void toggle_pause(void)
 {
     if (cur_stream)
         stream_pause(cur_stream);
     step = 0;
 }
 
-void step_to_next_frame(void)
+static void step_to_next_frame(void)
 {
     if (cur_stream) {
         if (cur_stream->paused)
@@ -2134,7 +2134,7 @@
     step = 1;
 }
 
-void do_exit(void)
+static void do_exit(void)
 {
     if (cur_stream) {
         stream_close(cur_stream);
@@ -2146,7 +2146,7 @@
     exit(0);
 }
 
-void toggle_audio_display(void)
+static void toggle_audio_display(void)
 {
     if (cur_stream) {
         cur_stream->show_audio = !cur_stream->show_audio;
@@ -2154,7 +2154,7 @@
 }
 
 /* handle an event sent by the GUI */
-void event_loop(void)
+static void event_loop(void)
 {
     SDL_Event event;
     double incr, pos, frac;
Index: ffserver.c
===================================================================
--- ffserver.c	(revision 5492)
+++ ffserver.c	(working copy)
@@ -3704,7 +3704,7 @@
 /* simplistic plugin support */
 
 #ifdef CONFIG_HAVE_DLOPEN
-void load_module(const char *filename)
+static void load_module(const char *filename)
 {
     void *dll;
     void (*init_func)(void);
Index: libavformat/udp.c
===================================================================
--- libavformat/udp.c	(revision 5492)
+++ libavformat/udp.c	(working copy)
@@ -51,7 +51,7 @@
 
 #ifdef CONFIG_IPV6
 
-int udp_ipv6_is_multicast_address(const struct sockaddr *addr) {
+static int udp_ipv6_is_multicast_address(const struct sockaddr *addr) {
     if (addr->sa_family == AF_INET)
         return IN_MULTICAST(ntohl(((struct sockaddr_in *)addr)->sin_addr.s_addr));
     if (addr->sa_family == AF_INET6)
@@ -59,7 +59,7 @@
     return -1;
 }
 
-int udp_ipv6_set_multicast_ttl(int sockfd, int mcastTTL, struct sockaddr *addr) {
+static int udp_ipv6_set_multicast_ttl(int sockfd, int mcastTTL, struct sockaddr *addr) {
     if (addr->sa_family == AF_INET) {
         if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &mcastTTL, sizeof(mcastTTL)) < 0) {
             perror("setsockopt(IP_MULTICAST_TTL)");
@@ -75,7 +75,7 @@
     return 0;
 }
 
-int udp_ipv6_join_multicast_group(int sockfd, struct sockaddr *addr) {
+static int udp_ipv6_join_multicast_group(int sockfd, struct sockaddr *addr) {
     struct ip_mreq   mreq;
     struct ipv6_mreq mreq6;
     if (addr->sa_family == AF_INET) {
@@ -97,7 +97,7 @@
     return 0;
 }
 
-int udp_ipv6_leave_multicast_group(int sockfd, struct sockaddr *addr) {
+static int udp_ipv6_leave_multicast_group(int sockfd, struct sockaddr *addr) {
     struct ip_mreq   mreq;
     struct ipv6_mreq mreq6;
     if (addr->sa_family == AF_INET) {
@@ -119,7 +119,7 @@
     return 0;
 }
 
-struct addrinfo* udp_ipv6_resolve_host(const char *hostname, int port, int type, int family, int flags) {
+static struct addrinfo* udp_ipv6_resolve_host(const char *hostname, int port, int type, int family, int flags) {
     struct addrinfo hints, *res = 0;
     int error;
     char sport[16];
@@ -144,7 +144,7 @@
     return res;
 }
 
-int udp_ipv6_set_remote_url(URLContext *h, const char *uri) {
+static int udp_ipv6_set_remote_url(URLContext *h, const char *uri) {
     UDPContext *s = h->priv_data;
     char hostname[256];
     int port;
@@ -158,7 +158,7 @@
     return 0;
 }
 
-int udp_ipv6_set_local(URLContext *h) {
+static int udp_ipv6_set_local(URLContext *h) {
     UDPContext *s = h->priv_data;
     int udp_fd = -1;
     struct sockaddr_storage clientaddr;
Index: libavformat/mpegts.c
===================================================================
--- libavformat/mpegts.c	(revision 5492)
+++ libavformat/mpegts.c	(working copy)
@@ -151,7 +151,7 @@
     }
 }
 
-MpegTSFilter *mpegts_open_section_filter(MpegTSContext *ts, unsigned int pid,
+static MpegTSFilter *mpegts_open_section_filter(MpegTSContext *ts, unsigned int pid,
                                          SectionCallback *section_cb, void *opaque,
                                          int check_crc)
 
@@ -183,7 +183,7 @@
     return filter;
 }
 
-MpegTSFilter *mpegts_open_pes_filter(MpegTSContext *ts, unsigned int pid,
+static MpegTSFilter *mpegts_open_pes_filter(MpegTSContext *ts, unsigned int pid,
                                      PESCallback *pes_cb,
                                      void *opaque)
 {
@@ -205,7 +205,7 @@
     return filter;
 }
 
-void mpegts_close_filter(MpegTSContext *ts, MpegTSFilter *filter)
+static void mpegts_close_filter(MpegTSContext *ts, MpegTSFilter *filter)
 {
     int pid;
 
@@ -609,7 +609,7 @@
     ts->pat_filter = NULL;
 }
 
-void mpegts_set_service(MpegTSContext *ts, int sid,
+static void mpegts_set_service(MpegTSContext *ts, int sid,
                         SetServiceCallback *set_service_cb, void *opaque)
 {
     ts->set_service_cb = set_service_cb;
@@ -696,7 +696,7 @@
 }
 
 /* scan services in a transport stream by looking at the SDT */
-void mpegts_scan_sdt(MpegTSContext *ts)
+static void mpegts_scan_sdt(MpegTSContext *ts)
 {
     ts->sdt_filter = mpegts_open_section_filter(ts, SDT_PID,
                                                 sdt_cb, ts, 1);
@@ -704,7 +704,7 @@
 
 /* scan services in a transport stream by looking at the PAT (better
    than nothing !) */
-void mpegts_scan_pat(MpegTSContext *ts)
+static void mpegts_scan_pat(MpegTSContext *ts)
 {
     ts->pat_filter = mpegts_open_section_filter(ts, PAT_PID,
                                                 pat_scan_cb, ts, 1);
Index: libavformat/movenc.c
===================================================================
--- libavformat/movenc.c	(revision 5492)
+++ libavformat/movenc.c	(working copy)
@@ -1341,7 +1341,7 @@
     return updateSize(pb, pos);
 }
 
-int mov_write_mdat_tag(ByteIOContext *pb, MOVContext* mov)
+static int mov_write_mdat_tag(ByteIOContext *pb, MOVContext* mov)
 {
     put_be32(pb, 8);    // placeholder for extended size field (64 bit)
     put_tag(pb, "wide");
Index: libavformat/aiff.c
===================================================================
--- libavformat/aiff.c	(revision 5492)
+++ libavformat/aiff.c	(working copy)
@@ -110,7 +110,7 @@
 }
 
 /* Returns the number of sound data frames or negative on error */
-unsigned int get_aiff_header(ByteIOContext *pb, AVCodecContext *codec,
+static unsigned int get_aiff_header(ByteIOContext *pb, AVCodecContext *codec,
                              int size, unsigned version)
 {
     AVExtFloat ext;
Index: libavformat/mpegtsenc.c
===================================================================
--- libavformat/mpegtsenc.c	(revision 5492)
+++ libavformat/mpegtsenc.c	(working copy)
@@ -34,7 +34,7 @@
 } MpegTSSection;
 
 /* NOTE: 4 bytes must be left at the end for the crc32 */
-void mpegts_write_section(MpegTSSection *s, uint8_t *buf, int len)
+static void mpegts_write_section(MpegTSSection *s, uint8_t *buf, int len)
 {
     unsigned int crc;
     unsigned char packet[TS_PACKET_SIZE];
@@ -89,7 +89,7 @@
     *q_ptr = q;
 }
 
-int mpegts_write_section1(MpegTSSection *s, int tid, int id,
+static int mpegts_write_section1(MpegTSSection *s, int tid, int id,
                           int version, int sec_num, int last_sec_num,
                           uint8_t *buf, int len)
 {
Index: libavformat/rtsp.c
===================================================================
--- libavformat/rtsp.c	(revision 5492)
+++ libavformat/rtsp.c	(working copy)
@@ -145,7 +145,7 @@
     char buf[256];
     int i;
     AVCodec *c;
-    char *c_name;
+    const char *c_name;
 
     /* Loop into AVRtpDynamicPayloadTypes[] and AVRtpPayloadTypes[] and
        see if we can handle this kind of payload */
@@ -169,7 +169,7 @@
 
     c = avcodec_find_decoder(codec->codec_id);
     if (c && c->name)
-        c_name = (char *)c->name;
+        c_name = c->name;
     else
         c_name = (char *)NULL;
 
@@ -255,7 +255,7 @@
 
 typedef struct attrname_map
 {
-    char *str;
+    const char *str;
     uint16_t type;
     uint32_t offset;
 } attrname_map_t;



More information about the ffmpeg-devel mailing list