changeset 1003:2d57ce58f576 libavformat

simplify AVFormatParameters NULL checks
author michael
date Sat, 11 Mar 2006 00:22:21 +0000
parents 56db80b1131e
children 409b399440a3
files audio.c grab.c grab_bktr.c img.c img2.c raw.c rtsp.c utils.c v4l2.c
diffstat 9 files changed, 18 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/audio.c	Wed Mar 08 21:51:39 2006 +0000
+++ b/audio.c	Sat Mar 11 00:22:21 2006 +0000
@@ -217,7 +217,7 @@
     AVStream *st;
     int ret;
 
-    if (!ap || ap->sample_rate <= 0 || ap->channels <= 0)
+    if (ap->sample_rate <= 0 || ap->channels <= 0)
         return -1;
 
     st = av_new_stream(s1, 0);
--- a/grab.c	Wed Mar 08 21:51:39 2006 +0000
+++ b/grab.c	Sat Mar 11 00:22:21 2006 +0000
@@ -68,7 +68,7 @@
     const char *video_device;
     int j;
 
-    if (!ap || ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0)
+    if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0)
         return -1;
 
     width = ap->width;
--- a/grab_bktr.c	Wed Mar 08 21:51:39 2006 +0000
+++ b/grab_bktr.c	Sat Mar 11 00:22:21 2006 +0000
@@ -245,7 +245,7 @@
     int format = -1;
     const char *video_device;
 
-    if (!ap || ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0)
+    if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0)
         return -1;
 
     width = ap->width;
--- a/img.c	Wed Mar 08 21:51:39 2006 +0000
+++ b/img.c	Sat Mar 11 00:22:21 2006 +0000
@@ -120,7 +120,7 @@
         return -ENOMEM;
     }
 
-    if (ap && ap->image_format)
+    if (ap->image_format)
         s->img_fmt = ap->image_format;
 
     pstrcpy(s->path, sizeof(s->path), s1->filename);
@@ -133,7 +133,7 @@
     else
         s->is_pipe = 1;
 
-    if (!ap || !ap->time_base.num) {
+    if (!ap->time_base.num) {
         st->codec->time_base= (AVRational){1,25};
     } else {
         st->codec->time_base= ap->time_base;
@@ -255,7 +255,7 @@
     int i;
 
     /* find output image format */
-    if (ap && ap->image_format) {
+    if (ap->image_format) {
         img_fmt = ap->image_format;
     } else {
         img_fmt = guess_image_format(s->filename);
--- a/img2.c	Wed Mar 08 21:51:39 2006 +0000
+++ b/img2.c	Sat Mar 11 00:22:21 2006 +0000
@@ -187,13 +187,13 @@
         st->need_parsing= 1;
     }
 
-    if (!ap || !ap->time_base.num) {
+    if (!ap->time_base.num) {
         av_set_pts_info(st, 60, 1, 25);
     } else {
         av_set_pts_info(st, 60, ap->time_base.num, ap->time_base.den);
     }
 
-    if(ap && ap->width && ap->height){
+    if(ap->width && ap->height){
         st->codec->width = ap->width;
         st->codec->height= ap->height;
     }
--- a/raw.c	Wed Mar 08 21:51:39 2006 +0000
+++ b/raw.c	Sat Mar 11 00:22:21 2006 +0000
@@ -48,7 +48,7 @@
     st = av_new_stream(s, 0);
     if (!st)
         return AVERROR_NOMEM;
-    if (ap) {
+
         id = s->iformat->value;
         if (id == CODEC_ID_RAWVIDEO) {
             st->codec->codec_type = CODEC_TYPE_VIDEO;
@@ -74,9 +74,6 @@
         default:
             return -1;
         }
-    } else {
-        return -1;
-    }
     return 0;
 }
 
@@ -289,7 +286,7 @@
 
     /* for mjpeg, specify frame rate */
     /* for mpeg4 specify it too (most mpeg4 streams dont have the fixed_vop_rate set ...)*/
-    if (ap && ap->time_base.num) {
+    if (ap->time_base.num) {
         av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
     } else if ( st->codec->codec_id == CODEC_ID_MJPEG ||
                 st->codec->codec_id == CODEC_ID_MPEG4 ||
--- a/rtsp.c	Wed Mar 08 21:51:39 2006 +0000
+++ b/rtsp.c	Sat Mar 11 00:22:21 2006 +0000
@@ -994,7 +994,7 @@
     rt->state = RTSP_STATE_IDLE;
     rt->seek_timestamp = 0; /* default is to start stream at position
                                zero */
-    if (ap && ap->initial_pause) {
+    if (ap->initial_pause) {
         /* do not start immediately */
     } else {
         if (rtsp_read_play(s) < 0) {
--- a/utils.c	Wed Mar 08 21:51:39 2006 +0000
+++ b/utils.c	Sat Mar 11 00:22:21 2006 +0000
@@ -465,6 +465,12 @@
 {
     int err;
     AVFormatContext *ic;
+    AVFormatParameters default_ap;
+
+    if(!ap){
+        ap=&default_ap;
+        memset(ap, 0, sizeof(default_ap));
+    }
 
     ic = av_alloc_format_context();
     if (!ic) {
--- a/v4l2.c	Wed Mar 08 21:51:39 2006 +0000
+++ b/v4l2.c	Sat Mar 11 00:22:21 2006 +0000
@@ -384,7 +384,7 @@
     uint32_t desired_format, capabilities;
     const char *video_device;
 
-    if (!ap || ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) {
+    if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) {
         av_log(s1, AV_LOG_ERROR, "Missing/Wrong parameters\n");
 
         return -1;