examples: set proper return codes in am7xxx-play
[libam7xxx.git] / examples / am7xxx-play.c
index f7e069a..56fd8b2 100644 (file)
@@ -291,6 +291,7 @@ static int am7xxx_play(const char *input_format_string,
        picture_raw = avcodec_alloc_frame();
        if (picture_raw == NULL) {
                fprintf(stderr, "cannot allocate the raw picture frame!");
+               ret = -ENOMEM;
                goto cleanup_output;
        }
 
@@ -298,6 +299,7 @@ static int am7xxx_play(const char *input_format_string,
        picture_scaled = avcodec_alloc_frame();
        if (picture_scaled == NULL) {
                fprintf(stderr, "cannot allocate the scaled picture!\n");
+               ret = -ENOMEM;
                goto cleanup_picture_raw;
        }
 
@@ -308,6 +310,7 @@ static int am7xxx_play(const char *input_format_string,
        out_buf = av_malloc(out_buf_size * sizeof(uint8_t));
        if (out_buf == NULL) {
                fprintf(stderr, "cannot allocate output data buffer!\n");
+               ret = -ENOMEM;
                goto cleanup_picture_scaled;
        }
 
@@ -329,6 +332,7 @@ static int am7xxx_play(const char *input_format_string,
                                            NULL, NULL, NULL);
        if (sw_scale_ctx == NULL) {
                fprintf(stderr, "cannot set up the rescaling context!\n");
+               ret = -EINVAL;
                goto cleanup_out_buf;
        }
 
@@ -564,6 +568,7 @@ static void usage(char *name)
        printf("\t\t\t\t\t1 - JPEG\n");
        printf("\t\t\t\t\t2 - NV12\n");
        printf("\t-q \t\t\tquality of jpeg sent to the device, between 1 and 100\n");
+       printf("\t-l <log level>\t\tthe verbosity level of libam7xxx output (0-5)\n");
        printf("\t-h \t\t\tthis help message\n");
        printf("\n\nEXAMPLES OF USE:\n");
        printf("\t%s -f x11grab -i :0.0 -o video_size=800x480\n", name);
@@ -585,11 +590,12 @@ int main(int argc, char *argv[])
        unsigned int rescale_method = SWS_BICUBIC;
        unsigned int upscale = 0;
        unsigned int quality = 95;
+       int log_level = AM7XXX_LOG_INFO;
        int format = AM7XXX_IMAGE_FORMAT_JPEG;
        am7xxx_context *ctx;
        am7xxx_device *dev;
 
-       while ((opt = getopt(argc, argv, "f:i:o:s:uF:q:h")) != -1) {
+       while ((opt = getopt(argc, argv, "f:i:o:s:uF:q:l:h")) != -1) {
                switch (opt) {
                case 'f':
                        input_format_string = strdup(optarg);
@@ -662,6 +668,13 @@ int main(int argc, char *argv[])
                                goto out;;
                        }
                        break;
+               case 'l':
+                       log_level = atoi(optarg);
+                       if (log_level < AM7XXX_LOG_FATAL || log_level > AM7XXX_LOG_TRACE) {
+                               fprintf(stderr, "Unsupported log level, falling back to AM7XXX_LOG_ERROR\n");
+                               log_level = AM7XXX_LOG_ERROR;
+                       }
+                       break;
                case 'h':
                        usage(argv[0]);
                        ret = 0;
@@ -713,6 +726,8 @@ int main(int argc, char *argv[])
                goto out;
        }
 
+       am7xxx_set_log_level(ctx, log_level);
+
        ret = am7xxx_open_device(ctx, &dev, 0);
        if (ret < 0) {
                perror("am7xxx_open_device");