diff recpt1/decoder.c @ 5:97fd2315114e

- now it can handle options. - applied channel patch. - some cleanups.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Tue, 17 Feb 2009 05:58:36 +0900
parents 43d177fa65c9
children b6607f6e2851
line wrap: on
line diff
--- a/recpt1/decoder.c	Tue Feb 17 01:46:54 2009 +0900
+++ b/recpt1/decoder.c	Tue Feb 17 05:58:36 2009 +0900
@@ -1,22 +1,62 @@
 #include <stdlib.h>
+#include <stdio.h>
 
 #include "decoder.h"
 
 decoder *
-b25_startup(void)
+b25_startup(decoder_options *opt)
 {
     decoder *dec = calloc(1, sizeof(decoder));
     int code;
+    const char *err = NULL;
 
     dec->b25 = create_arib_std_b25();
-    dec->b25->set_multi2_round(dec->b25, 4); //xxx round should be configurable
-    dec->b25->set_strip(dec->b25, 0); //ditto
-    dec->b25->set_emm_proc(dec->b25, 0); //ditto
+    if(!dec->b25) {
+        err = "create_arib_std_b25 failed";
+        goto error;
+    }
+
+    code = dec->b25->set_multi2_round(dec->b25, opt->round);
+    if(code < 0) {
+        err = "set_multi2_round failed";
+        goto error;
+    }
+
+    code = dec->b25->set_strip(dec->b25, opt->strip);
+    if(code < 0) {
+        err = "set_strip failed";
+        goto error;
+    }
+
+    code = dec->b25->set_emm_proc(dec->b25, opt->emm);
+    if(code < 0) {
+        err = "set_emm_proc failed";
+        goto error;
+    }
+
     dec->bcas = create_b_cas_card();
+    if(!dec->bcas) {
+        err = "create_b_cas_card failed";
+        goto error;
+    }
     code = dec->bcas->init(dec->bcas);
+    if(code < 0) {
+        err = "bcas->init failed";
+        goto error;
+    }
+
     code = dec->b25->set_b_cas_card(dec->b25, dec->bcas);
+    if(code < 0) {
+        err = "set_b_cas_card failed";
+        goto error;
+    }
 
     return dec;
+
+error:
+    fprintf(stderr, "%s\n", err);
+    free(dec);
+    return NULL;
 }
 
 int
@@ -32,25 +72,39 @@
 int
 b25_decode(decoder *dec, ARIB_STD_B25_BUFFER *sbuf, ARIB_STD_B25_BUFFER *dbuf)
 {
-    int code;
+  int code;
+
+  code = dec->b25->put(dec->b25, sbuf);
+  if(code < 0) {
+      fprintf(stderr, "b25->put failed\n");
+      return code;
+  }
 
-    code = dec->b25->put(dec->b25, sbuf);
-    if(code < 0)
-        return code;
+  code = dec->b25->get(dec->b25, dbuf);
+  if(code < 0) {
+      fprintf(stderr, "b25->get failed\n");
+      return code;
+  }
 
-    code = dec->b25->get(dec->b25, dbuf);
-    return code;
+  return code;
 }
 
 int
 b25_finish(decoder *dec, ARIB_STD_B25_BUFFER *sbuf, ARIB_STD_B25_BUFFER *dbuf)
 {
-    int code;
+  int code;
+
+  code = dec->b25->flush(dec->b25);
+  if(code < 0) {
+      fprintf(stderr, "b25->flush failed\n");
+      return code;
+  }
 
-    code = dec->b25->flush(dec->b25);
-    if(code < 0)
-        return code;
+  code = dec->b25->get(dec->b25, dbuf);
+  if(code < 0) {
+      fprintf(stderr, "b25->get failed\n");
+      return code;
+  }
 
-    code = dec->b25->get(dec->b25, dbuf);
-    return code;
+  return code;
 }