Ticket #5905: fw_tester.patch

File fw_tester.patch, 4.8 KB (added by mythtv@…, 11 years ago)

Patch to output mpeg2 stream from firewire_tester

  • .c

    old new  
    33 *  Copyright (c) 2006 by Jim Westfall
    44 *  Distributed as part of MythTV under GPL v2 and later.
    55 *
    6  *  $ gcc -Wall -o my_firewire_tester my_firewire_tester.c -liec61883 -lraw1394
     6 *  $ gcc -Wall -o firewire_tester firewire_tester.c -liec61883 -lraw1394
    77 */
    88
    99#include <unistd.h>
     
    1919#define ACTION_TEST_P2P     1
    2020#define ACTION_FIX_BCAST    2
    2121#define ACTION_RESET_BUS    3
    22 #define ACTION_OUTPUT_P2P   4
    2322
    2423#define SYNC_BYTE           0x47
    2524#define MIN_PACKETS         25
     
    3029int verbose = 0;
    3130int sync_failed = 0;
    3231int nodata = 0;
    33 int run = 0;
    3432
    3533static int read_packet (unsigned char *tspacket, int len,
    3634                        unsigned int dropped, void *callback_data)
     
    5351    return 1;
    5452}
    5553
    56 static int fwrite_packet (unsigned char *tspacket, int len,
    57                         unsigned int dropped, void *callback_data)
    58 {
    59     int n;
    60     FILE *fp = (FILE *) callback_data;
    61 
    62     if (dropped)
    63     {
    64         fprintf(stderr, "Dropped %d packet(s).\n", dropped);
    65         return 0;
    66     }
    67 
    68     if (tspacket[0] != SYNC_BYTE)
    69     {
    70         sync_failed = 1;
    71         return 0;
    72     }
    73     nodata = 0;
    74     n = fwrite(tspacket, sizeof(char), 188, fp);
    75     //fprintf(stderr, "fwrite_packets: wrote %d of %d\n", n, len);
    76     return(n == len ? 0 : 1);
    77 }
    78 
    7954int test_connection(raw1394handle_t handle, int channel)
    8055{
    8156    int count = 0;
     
    235210    return 0;
    236211}
    237212
    238 // create and test a p2p connection, copy packets to stdout
    239 // returns 1 on success, 0 on failure
    240 int output_p2p(raw1394handle_t handle, nodeid_t node) {
    241     int channel, count, success = 0;
    242     int retry = 0;
    243     FILE *fp = stdout;
    244     iec61883_mpeg2_t mpeg;
    245     struct timeval tv;
    246     fd_set rfds;
    247     channel = node;
    248     int fd = raw1394_get_fd(handle);
    249 
    250     sync_failed = 0;
    251 
    252     VERBOSE("P2P: Creating, node %d, channel %d\n", node, channel);
    253     fflush(stdout);
    254  
    255     // make connection
    256     if (iec61883_cmp_create_p2p_output(handle, node | 0xffc0, 0, channel,
    257                                        1 /* fix me, speed */ ) != 0)
    258     {
    259         fprintf(stderr, "iec61883_cmp_create_p2p_output failed\n");
    260         return 0;
    261     }
    262     mpeg = iec61883_mpeg2_recv_init(handle, fwrite_packet, (void*) fp);
    263     run = 1;
    264     iec61883_mpeg2_recv_start(mpeg, channel);
    265     while(run && retry < 2 && !sync_failed && nodata < MAX_NODATA)
    266     {
    267         FD_ZERO(&rfds);
    268         FD_SET(fd, &rfds);
    269         tv.tv_sec = 1;
    270         tv.tv_usec = 0;
    271 
    272         if (select(fd + 1, &rfds, NULL, NULL, &tv) > 0)
    273         {
    274              nodata++;
    275              raw1394_loop_iterate(handle);
    276         }
    277         else
    278         {
    279             retry++;
    280         }
    281     }
    282     iec61883_mpeg2_recv_stop(mpeg);
    283     iec61883_mpeg2_close(mpeg);
    284 
    285     if (sync_failed)
    286         return 0;
    287 
    288     return count;
    289 
    290     VERBOSE("P2P: Disconnecting.\n");
    291     iec61883_cmp_disconnect(handle, node | 0xffc0, 0,
    292                             raw1394_get_local_id (handle),
    293                             -1, channel, 0);
    294     return success;
    295 }
    296 
    297213void usage(void) {
    298214    printf("firewire_tester <action> -n <node> [-P <port>] [-r <n>] [-v]\n");
    299215    printf(" Actions: (one is required)\n");
     
    303219    printf("    -R          - reset the firewire bus\n");
    304220    printf(" Options\n");
    305221    printf("    -n <node>   - firewire node, required\n");
    306     printf("    -o          - write packets to stdout using p2p connection\n");
    307222    printf("    -P <port>   - firewire port, default 0\n");
    308223    printf("    -r <n>      - run action <n> times, default 1\n");
    309224    printf("    -v          - verbose\n");
     
    319234    int action = ACTION_NONE;
    320235
    321236    opterr = 0;
    322     while ((c = getopt(argc, argv, "Bbn:opP:r:Rv")) != -1)
     237    while ((c = getopt(argc, argv, "Bbn:pP:r:Rv")) != -1)
    323238    {
    324239        switch (c)
    325240        {
     
    354269                }
    355270                break;
    356271
    357             // output packets using p2p connection
    358             case 'o':
    359                 if (action != ACTION_NONE)
    360                 {
    361                     printf("Invalid command line\n");
    362                     usage();
    363                 }
    364                 action = ACTION_OUTPUT_P2P;
    365                 break;
    366 
    367272            // set the port, optional
    368273            case 'P':
    369274                port = atoi(optarg);
     
    463368                printf("Bus reset failed: %d\n", errno);
    464369            }
    465370            break;
    466         case ACTION_OUTPUT_P2P:
    467             runs = 1;
    468             fprintf(stderr,
    469                     "Action: Output P2P packets using node %d, channel %d\n",
    470                     node, node);
    471             success = output_p2p(handle, node);
    472             break;
    473371    }
    474372
    475373    VERBOSE("raw1394: Releasing handle.\n");