summaryrefslogtreecommitdiffstats
path: root/ext/raw1394/gst1394probe.c
blob: ee51ba0c6875ed6ce27dc73cd2dd94b2020e8331 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* GStreamer
 * Copyright (C) 2007 Julien Puydt <jpuydt@free.fr>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <libavc1394/avc1394.h>
#include <libavc1394/avc1394_vcr.h>
#include <libavc1394/rom1394.h>
#include <libraw1394/raw1394.h>

#include <gst/gst.h>

#include "gst1394probe.h"
#include "gst/interfaces/propertyprobe.h"

static GValueArray *
gst_1394_get_guid_array (void)
{
  GValueArray *result = NULL;
  raw1394handle_t handle = NULL;
  int num_ports = 0;
  int port = 0;
  int num_nodes = 0;
  int node = 0;
  rom1394_directory directory;
  GValue value = { 0, };

  handle = raw1394_new_handle ();

  if (handle == NULL)
    return NULL;

  num_ports = raw1394_get_port_info (handle, NULL, 0);
  for (port = 0; port < num_ports; port++) {
    if (raw1394_set_port (handle, port) >= 0) {
      num_nodes = raw1394_get_nodecount (handle);
      for (node = 0; node < num_nodes; node++) {
        rom1394_get_directory (handle, node, &directory);
        if (rom1394_get_node_type (&directory) == ROM1394_NODE_TYPE_AVC &&
            avc1394_check_subunit_type (handle, node,
                AVC1394_SUBUNIT_TYPE_VCR)) {
          if (result == NULL)
            result = g_value_array_new (3);     /* looks like a sensible default */
          g_value_init (&value, G_TYPE_UINT64);
          g_value_set_uint64 (&value, rom1394_get_guid (handle, node));
          g_value_array_append (result, &value);
          g_value_unset (&value);
        }
      }
    }
  }

  return result;
}

static const GList *
gst_1394_property_probe_get_properties (GstPropertyProbe * probe)
{
  static GList *result = NULL;
  GObjectClass *klass = NULL;
  GParamSpec *spec = NULL;

  if (result == NULL) {
    klass = G_OBJECT_GET_CLASS (probe);
    spec = g_object_class_find_property (klass, "guid");
    result = g_list_append (result, spec);
  }

  return result;
}

static void
gst_1394_property_probe_probe_property (GstPropertyProbe * probe, guint prop_id,
    const GParamSpec * pspec)
{
  if (!g_str_equal (pspec->name, "guid"))
    G_OBJECT_WARN_INVALID_PROPERTY_ID (probe, prop_id, pspec);
}

static gboolean
gst_1394_property_probe_needs_probe (GstPropertyProbe * probe, guint prop_id,
    const GParamSpec * pspec)
{
  return TRUE;
}

static GValueArray *
gst_1394_property_probe_get_values (GstPropertyProbe * probe, guint prop_id,
    const GParamSpec * pspec)
{
  GValueArray *result = NULL;

  if (!g_str_equal (pspec->name, "guid")) {
    G_OBJECT_WARN_INVALID_PROPERTY_ID (probe, prop_id, pspec);
    return NULL;
  }

  result = gst_1394_get_guid_array ();

  if (result == NULL)
    GST_LOG_OBJECT (probe, "No guid found");

  return result;
}

static void
gst_1394_property_probe_interface_init (GstPropertyProbeInterface * iface)
{
  iface->get_properties = gst_1394_property_probe_get_properties;
  iface->probe_property = gst_1394_property_probe_probe_property;
  iface->needs_probe = gst_1394_property_probe_needs_probe;
  iface->get_values = gst_1394_property_probe_get_values;
}

void
gst_1394_type_add_property_probe_interface (GType type)
{
  static const GInterfaceInfo probe_iface_info = {
    (GInterfaceInitFunc) gst_1394_property_probe_interface_init,
    NULL,
    NULL,
  };

  g_type_add_interface_static (type, GST_TYPE_PROPERTY_PROBE,
      &probe_iface_info);
}