| 1 |
/* |
| 2 |
* libiec61883 - Linux IEEE 1394 streaming media library. |
| 3 |
* Copyright (C) 2004 Dan Dennedy |
| 4 |
* |
| 5 |
* This example demonstrates creating a process to host plug control registers |
| 6 |
* used for connection management procedures as described in IEC 61883-1. |
| 7 |
* This can be expanded to run as a daemon, use syslog, and define some |
| 8 |
* interprocess communication for the addition and removal of plug control |
| 9 |
* registers. libiec61883 plug functions are not thread safe and manipulations |
| 10 |
* should be protected. |
| 11 |
* |
| 12 |
* This library is free software; you can redistribute it and/or |
| 13 |
* modify it under the terms of the GNU Lesser General Public |
| 14 |
* License as published by the Free Software Foundation; either |
| 15 |
* version 2.1 of the License, or (at your option) any later version. |
| 16 |
* |
| 17 |
* This library is distributed in the hope that it will be useful, |
| 18 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 |
* Lesser General Public License for more details. |
| 21 |
* |
| 22 |
* You should have received a copy of the GNU Lesser General Public |
| 23 |
* License along with this library; if not, write to the Free Software |
| 24 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 |
*/ |
| 26 |
|
| 27 |
#include "../src/iec61883.h" |
| 28 |
#include <stdio.h> |
| 29 |
#include <sys/select.h> |
| 30 |
#include <signal.h> |
| 31 |
#include <string.h> |
| 32 |
#include <stdlib.h> |
| 33 |
|
| 34 |
static int g_done = 0; |
| 35 |
|
| 36 |
static void sighandler (int sig) |
| 37 |
{ |
| 38 |
g_done = 1; |
| 39 |
} |
| 40 |
|
| 41 |
int main (int argc, char *argv[]) |
| 42 |
{ |
| 43 |
raw1394handle_t handle = raw1394_new_handle_on_port (0); |
| 44 |
|
| 45 |
if (handle) { |
| 46 |
int fd = raw1394_get_fd (handle); |
| 47 |
struct timeval tv; |
| 48 |
fd_set rfds; |
| 49 |
int result; |
| 50 |
|
| 51 |
signal (SIGINT, sighandler); |
| 52 |
signal (SIGTERM, sighandler); |
| 53 |
|
| 54 |
if ((result = iec61883_plug_impr_init (handle, IEC61883_DATARATE_400)) < 0) { |
| 55 |
fprintf (stderr, "iec61883_plug_impr_init failed: %d\n", result); |
| 56 |
raw1394_destroy_handle (handle); |
| 57 |
return 1; |
| 58 |
} |
| 59 |
|
| 60 |
if ((result = iec61883_plug_ipcr_add (handle, 1 /* online */)) < 0) { |
| 61 |
fprintf (stderr, "iec61883_plug_add_ipcr failed: %d\n", result); |
| 62 |
raw1394_destroy_handle (handle); |
| 63 |
return 1; |
| 64 |
} |
| 65 |
|
| 66 |
if ((result = iec61883_plug_ompr_init (handle, IEC61883_DATARATE_400, 63)) < 0) { |
| 67 |
fprintf (stderr, "iec61883_plug_ompr_init failed: %d\n", result); |
| 68 |
raw1394_destroy_handle (handle); |
| 69 |
return 1; |
| 70 |
} |
| 71 |
|
| 72 |
/* 968 = 5 transport stream packets + CIP header, payload is in quadlets */ |
| 73 |
/* even after reading the spec I still don't understand the overhead |
| 74 |
parameter. Besides, the iso packet headers, where does the overhead |
| 75 |
come from? */ |
| 76 |
if ((result = iec61883_plug_opcr_add (handle, 1 /* online */, |
| 77 |
IEC61883_OVERHEAD_512, 968/4)) < 0) { |
| 78 |
fprintf (stderr, "iec61883_plug_add_opcr failed: %d\n", result); |
| 79 |
raw1394_destroy_handle (handle); |
| 80 |
return 1; |
| 81 |
} |
| 82 |
|
| 83 |
do { |
| 84 |
FD_ZERO (&rfds); |
| 85 |
FD_SET (fd, &rfds); |
| 86 |
tv.tv_sec = 0; |
| 87 |
tv.tv_usec = 20000; |
| 88 |
|
| 89 |
if (select (fd + 1, &rfds, NULL, NULL, &tv) > 0) |
| 90 |
raw1394_loop_iterate (handle); |
| 91 |
|
| 92 |
} while (g_done == 0); |
| 93 |
|
| 94 |
fprintf (stderr, "done.\n"); |
| 95 |
|
| 96 |
iec61883_plug_impr_close (handle); |
| 97 |
iec61883_plug_ompr_close (handle); |
| 98 |
|
| 99 |
raw1394_destroy_handle (handle); |
| 100 |
|
| 101 |
} else { |
| 102 |
fprintf (stderr, "Failed to get libraw1394 handle\n"); |
| 103 |
return 1; |
| 104 |
} |
| 105 |
|
| 106 |
return 0; |
| 107 |
} |