/*
 * libavc1394 - GNU/Linux 1394 AV/C Library
 *
 * Originally written by Andreas Micklei <andreas.micklei@ivistar.de>
 * Currently maintained by Dan Dennedy <dan@dennedy.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser 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
 */

#ifndef AVC1394_H
#define AVC1394_H 1


#include <libraw1394/raw1394.h>

/* AV/C response codes */
#define AVC1394_RESPONSE_NOT_IMPLEMENTED 0x08000000
#define AVC1394_RESPONSE_ACCEPTED 0x09000000
#define AVC1394_RESPONSE_REJECTED 0x0A000000
#define AVC1394_RESPONSE_IN_TRANSITION 0x0B000000
#define AVC1394_RESPONSE_IMPLEMENTED 0x0C000000
#define AVC1394_RESPONSE_STABLE 0x0C000000
#define AVC1394_RESPONSE_CHANGED 0x0D000000
#define AVC1394_RESPONSE_INTERIM 0x0F000000

/* variants */
#define AVC1394_RESP_NOT_IMPLEMENTED 0x08
#define AVC1394_RESP_ACCEPTED 0x09
#define AVC1394_RESP_REJECTED 0x0A
#define AVC1394_RESP_IN_TRANSITION 0x0B
#define AVC1394_RESP_IMPLEMENTED 0x0C
#define AVC1394_RESP_STABLE 0x0C
#define AVC1394_RESP_CHANGED 0x0D
#define AVC1394_RESP_INTERIM 0x0F

/* AV/C Mask macros */
#define AVC1394_MASK_START(x) ((x) & 0xF0000000)
#define AVC1394_MASK_CTYPE(x) ((x) & 0x0F000000)
#define AVC1394_MASK_RESPONSE(x) ((x) & 0x0F000000)
#define AVC1394_MASK_SUBUNIT_TYPE(x) ((x) & 0x00F80000)
#define AVC1394_MASK_SUBUNIT_ID(x) ((x) & 0x00070000)
#define AVC1394_MASK_OPCODE(x) ((x) & 0x0000FF00)
#define AVC1394_MASK_OPERAND0(x) ((x) & 0x000000FF)
#define AVC1394_MASK_OPERAND(x, n) ((x) & (0xFF000000 >> ((((n)-1)%4)*8)))
#define AVC1394_MASK_RESPONSE_OPERAND(x, n) ((x) & (0xFF000000 >> (((n)%4)*8)))

/* AV/C Mask and shift macros */
#define AVC1394_GET_CTYPE(x) (((x) & 0x0F000000) >> 24)
#define AVC1394_GET_RESPONSE(x) (((x) & 0x0F000000) >> 24)
#define AVC1394_GET_SUBUNIT_TYPE(x) (((x) & 0x00F80000) >> 19)
#define AVC1394_GET_SUBUNIT_ID(x) (((x) & 0x00070000) >> 16)
#define AVC1394_GET_OPCODE(x) (((x) & 0x0000FF00) >> 8)
#define AVC1394_GET_OPERAND0(x) ((x) & 0x000000FF)
#define AVC1394_GET_OPERAND(x, n) (((x) & (0xFF000000 >> ((((n)-1)%4)*8))) >> ((((n)-1)%4)*8))
#define AVC1394_GET_RESPONSE_OPERAND(x, n) (((x) & (0xFF000000 >> (((n)%4)*8))) >> (((3-(n))%4)*8))

/* AV/C command types */
#define AVC1394_CTYPE_CONTROL 0x00000000
#define AVC1394_CTYPE_STATUS 0x01000000
#define AVC1394_CTYPE_SPECIFIC_INQUIRY 0x02000000
#define AVC1394_CTYPE_NOTIFY 0x03000000
#define AVC1394_CTYPE_GENERAL_INQUIRY 0x04000000

#define AVC1394_CTYP_CONTROL 0
#define AVC1394_CTYP_STATUS 1
#define AVC1394_CTYP_SPECIFIC_INQUIRY 2
#define AVC1394_CTYP_NOTIFY 3
#define AVC1394_CTYP_GENERAL_INQUIRY 4

/* AV/C subunit types */
#define AVC1394_SUBUNIT_TYPE_VIDEO_MONITOR (0 <<19)
#define AVC1394_SUBUNIT_TYPE_AUDIO (1 <<19)
#define AVC1394_SUBUNIT_TYPE_PRINTER (2 <<19)
#define AVC1394_SUBUNIT_TYPE_DISC_RECORDER (3 <<19)
#define AVC1394_SUBUNIT_TYPE_TAPE_RECORDER (4 <<19)
#define AVC1394_SUBUNIT_TYPE_VCR (4 <<19)
#define AVC1394_SUBUNIT_TYPE_TUNER (5 <<19)
#define AVC1394_SUBUNIT_TYPE_CA (6 <<19)
#define AVC1394_SUBUNIT_TYPE_VIDEO_CAMERA (7 <<19)
#define AVC1394_SUBUNIT_TYPE_PANEL (9 <<19)
#define AVC1394_SUBUNIT_TYPE_BULLETIN_BOARD (0xA <<19)
#define AVC1394_SUBUNIT_TYPE_CAMERA_STORAGE (0xB <<19)
#define AVC1394_SUBUNIT_TYPE_MUSIC (0xC <<19)
#define AVC1394_SUBUNIT_TYPE_VENDOR_UNIQUE (0x1C <<19)
#define AVC1394_SUBUNIT_TYPE_EXTENDED (0x1E <<19)	/* Not implemented */
#define AVC1394_SUBUNIT_TYPE_UNIT (0x1F <<19)

/* variants */
#define AVC1394_SUBUNIT_VIDEO_MONITOR 0
#define AVC1394_SUBUNIT_DISC_RECORDER 3
#define AVC1394_SUBUNIT_TAPE_RECORDER 4
#define AVC1394_SUBUNIT_VCR 4
#define AVC1394_SUBUNIT_TUNER 5
#define AVC1394_SUBUNIT_VIDEO_CAMERA 7
#define AVC1394_SUBUNIT_VENDOR_UNIQUE 0x1C
#define AVC1394_SUBUNIT_EXTENDED 0x1E	/* Not implemented */
#define AVC1394_SUBUNIT_UNIT 0x1F

/* AV/C subunit IDs */
#define AVC1394_SUBUNIT_ID_0 (0 << 16)
#define AVC1394_SUBUNIT_ID_1 (1 << 16)
#define AVC1394_SUBUNIT_ID_2 (2 << 16)
#define AVC1394_SUBUNIT_ID_3 (3 << 16)
#define AVC1394_SUBUNIT_ID_4 (4 << 16)
#define AVC1394_SUBUNIT_ID_EXTENDED (5 <<16)	/* Not implemented */
#define AVC1394_SUBUNIT_ID_IGNORE (7 << 16)

/* AV/C subunit capabilities */
#define AVC1394_SUBUNIT_MUSIC_CAPABILITY_GENERAL (1<<0)
#define AVC1394_SUBUNIT_MUSIC_CAPABILITY_AUDIO (1<<1)
#define AVC1394_SUBUNIT_MUSIC_CAPABILITY_MIDI (1<<2)
#define AVC1394_SUBUNIT_MUSIC_CAPABILITY_SMPTE (1<<3)
#define AVC1394_SUBUNIT_MUSIC_CAPABILITY_SAMPLECOUNT (1<<4)
#define AVC1394_SUBUNIT_MUSIC_CAPABILITY_AUDIOSYNC (1<<5)
#define AVC1394_SUBUNIT_MUSIC_CAPABILITY_RESERVED (1<<6)
#define AVC1394_SUBUNIT_MUSIC_CAPABILITY_MORE (1<<7)

#define AVC1394_SUBUNIT_MUSIC_CAPABILITY_NONBLOCKING (1<<0)
#define AVC1394_SUBUNIT_MUSIC_CAPABILITY_BLOCKING (1<<1)

#define AVC1394_SUBUNIT_MUSIC_CAPABILITY_AUDIOSYNC_BUS (1<<0)
#define AVC1394_SUBUNIT_MUSIC_CAPABILITY_AUDIOSYNC_EXTERNAL (1<<0)

/* AV/C Unit commands */
#define AVC1394_COMMAND_CHANNEL_USAGE 0x00001200
#define AVC1394_COMMAND_CONNECT 0x00002400
#define AVC1394_COMMAND_CONNECT_AV 0x00002000
#define AVC1394_COMMAND_CONNECTIONS 0x00002200
#define AVC1394_COMMAND_DIGITAL_INPUT 0x00001100
#define AVC1394_COMMAND_DIGITAL_OUTPUT 0x00001000
#define AVC1394_COMMAND_DISCONNECT 0x00002500
#define AVC1394_COMMAND_DISCONNECT_AV 0x00002100
#define AVC1394_COMMAND_INPUT_PLUG_SIGNAL_FORMAT 0x00001900
#define AVC1394_COMMAND_OUTPUT_PLUG_SIGNAL_FORMAT 0x00001800
#define AVC1394_COMMAND_SUBUNIT_INFO 0x00003100
#define AVC1394_COMMAND_UNIT_INFO 0x00003000

/* variants */
#define AVC1394_CMD_CHANNEL_USAGE 0x12
#define AVC1394_CMD_CONNECT 0x24
#define AVC1394_CMD_CONNECT_AV 0x20
#define AVC1394_CMD_CONNECTIONS 0x22
#define AVC1394_CMD_DIGITAL_INPUT 0x11
#define AVC1394_CMD_DIGITAL_OUTPUT 0x10
#define AVC1394_CMD_DISCONNECT 0x25
#define AVC1394_CMD_DISCONNECT_AV 0x21
#define AVC1394_CMD_INPUT_PLUG_SIGNAL_FORMAT 0x19
#define AVC1394_CMD_OUTPUT_PLUG_SIGNAL_FORMAT 0x18
#define AVC1394_CMD_SUBUNIT_INFO 0x31
#define AVC1394_CMD_UNIT_INFO 0x30

/* AV/C Common unit and subunit commands */
#define AVC1394_COMMAND_OPEN_DESCRIPTOR 0x00000800
#define AVC1394_COMMAND_READ_DESCRIPTOR 0x00000900
#define AVC1394_COMMAND_WRITE_DESCRIPTOR 0x00000A00
#define AVC1394_COMMAND_SEARCH_DESCRIPTOR 0x00000B00
#define AVC1394_COMMAND_OBJECT_NUMBER_SELECT 0x00000D00
#define AVC1394_COMMAND_POWER 0x0000B200
#define AVC1394_COMMAND_RESERVE 0x00000100
#define AVC1394_COMMAND_PLUG_INFO 0x00000200
#define AVC1394_COMMAND_VENDOR_DEPENDENT 0x00000000

/* variants */
#define AVC1394_CMD_OPEN_DESCRIPTOR 0x08
#define AVC1394_CMD_READ_DESCRIPTOR 0x09
#define AVC1394_CMD_WRITE_DESCRIPTOR 0x0A
#define AVC1394_CMD_SEARCH_DESCRIPTOR 0x0B
#define AVC1394_CMD_OBJECT_NUMBER_SELECT 0x0D
#define AVC1394_CMD_POWER 0xB2
#define AVC1394_CMD_RESERVE 0x01
#define AVC1394_CMD_PLUG_INFO 0x02
#define AVC1394_CMD_VENDOR_DEPENDENT 0x00

/* power operands */
#define AVC1394_CMD_OPERAND_POWER_ON 0x70
#define AVC1394_CMD_OPERAND_POWER_OFF 0x60

#define AVC1394_OPERAND_UNIT_INFO_EXTENSION_CODE 7

/* AV/C Common unit and subunit command operands */
#define AVC1394_OPERAND_DESCRIPTOR_TYPE_SUBUNIT_IDENTIFIER_DESCRIPTOR 0x00
#define AVC1394_OPERAND_DESCRIPTOR_TYPE_OBJECT_LIST_DESCRIPTOR_ID 0x10
#define AVC1394_OPERAND_DESCRIPTOR_TYPE_OBJECT_LIST_DESCRIPTOR_TYPE 0x11
#define AVC1394_OPERAND_DESCRIPTOR_TYPE_OBJECT_ENTRY_DESCRIPTOR_POSITION 0x20
#define AVC1394_OPERAND_DESCRIPTOR_TYPE_OBJECT_ENTRY_DESCRIPTOR_ID 0x21
#define AVC1394_OPERAND_DESCRIPTOR_SUBFUNCTION_CLOSE 0x00
#define AVC1394_OPERAND_DESCRIPTOR_SUBFUNCTION_READ_OPEN 0x01
#define AVC1394_OPERAND_DESCRIPTOR_SUBFUNCTION_WRITE_OPEN 0x03

/* VCR subunit commands (Alphabetically) */
#define AVC1394_VCR_COMMAND_ANALOG_AUDIO_OUTPUT_MODE 0x000007000
#define AVC1394_VCR_COMMAND_AREA_MODE 0x000007200
#define AVC1394_VCR_COMMAND_ABSOLUTE_TRACK_NUMBER 0x000005200
#define AVC1394_VCR_COMMAND_AUDIO_MODE 0x000007100
#define AVC1394_VCR_COMMAND_BACKWARD 0x000005600
#define AVC1394_VCR_COMMAND_BINARY_GROUP 0x000005A00
#define AVC1394_VCR_COMMAND_EDIT_MODE 0x000004000
#define AVC1394_VCR_COMMAND_FORWARD 0x000005500
#define AVC1394_VCR_COMMAND_INPUT_SIGNAL_MODE 0x000007900
#define AVC1394_VCR_COMMAND_LOAD_MEDIUM 0x00000C100
#define AVC1394_VCR_COMMAND_MARKER 0x00000CA00
#define AVC1394_VCR_COMMAND_MEDIUM_INFO 0x00000DA00
#define AVC1394_VCR_COMMAND_OPEN_MIC 0x000006000
#define AVC1394_VCR_COMMAND_OUTPUT_SIGNAL_MODE 0x000007800
#define AVC1394_VCR_COMMAND_PLAY 0x00000C300
#define AVC1394_VCR_COMMAND_PRESET 0x000004500
#define AVC1394_VCR_COMMAND_READ_MIC 0x000006100
#define AVC1394_VCR_COMMAND_RECORD 0x00000C200
#define AVC1394_VCR_COMMAND_RECORDING_DATE 0x000005300
#define AVC1394_VCR_COMMAND_RECORDING_SPEED 0x00000DB00
#define AVC1394_VCR_COMMAND_RECORDING_TIME 0x000005400
#define AVC1394_VCR_COMMAND_RELATIVE_TIME_COUNTER 0x000005700
#define AVC1394_VCR_COMMAND_SEARCH_MODE 0x000005000
#define AVC1394_VCR_COMMAND_SMPTE_EBU_RECORDING_TIME 0x000005C00
#define AVC1394_VCR_COMMAND_SMPTE_EBU_TIME_CODE 0x000005900
#define AVC1394_VCR_COMMAND_TAPE_PLAYBACK_FORMAT 0x00000D300
#define AVC1394_VCR_COMMAND_TAPE_RECORDING_FORMAT 0x00000D200
#define AVC1394_VCR_COMMAND_TIME_CODE 0x000005100
#define AVC1394_VCR_COMMAND_TRANSPORT_STATE 0x00000D000
#define AVC1394_VCR_COMMAND_WIND 0x00000C400
#define AVC1394_VCR_COMMAND_WRITE_MIC 0x000006200

/* variants */
#define AVC1394_VCR_CMD_ANALOG_AUDIO_OUTPUT_MODE 0x70
#define AVC1394_VCR_CMD_AREA_MODE 0x72
#define AVC1394_VCR_CMD_ABSOLUTE_TRACK_NUMBER 0x52
#define AVC1394_VCR_CMD_AUDIO_MODE 0x71
#define AVC1394_VCR_CMD_BACKWARD 0x56
#define AVC1394_VCR_CMD_BINARY_GROUP 0x5A
#define AVC1394_VCR_CMD_EDIT_MODE 0x40
#define AVC1394_VCR_CMD_FORWARD 0x55
#define AVC1394_VCR_CMD_INPUT_SIGNAL_MODE 0x79
#define AVC1394_VCR_CMD_LOAD_MEDIUM 0xC1
#define AVC1394_VCR_CMD_MARKER 0xCA
#define AVC1394_VCR_CMD_MEDIUM_INFO 0xDA
#define AVC1394_VCR_CMD_OPEN_MIC 0x60
#define AVC1394_VCR_CMD_OUTPUT_SIGNAL_MODE 0x78
#define AVC1394_VCR_CMD_PLAY 0xC3
#define AVC1394_VCR_CMD_PRESET 0x45
#define AVC1394_VCR_CMD_READ_MIC 0x61
#define AVC1394_VCR_CMD_RECORD 0xC2
#define AVC1394_VCR_CMD_RECORDING_DATE 0x53
#define AVC1394_VCR_CMD_RECORDING_SPEED 0xDB
#define AVC1394_VCR_CMD_RECORDING_TIME 0x54
#define AVC1394_VCR_CMD_RELATIVE_TIME_COUNTER 0x57
#define AVC1394_VCR_CMD_SEARCH_MODE 0x50
#define AVC1394_VCR_CMD_SMPTE_EBU_RECORDING_TIME 0x5C
#define AVC1394_VCR_CMD_SMPTE_EBU_TIME_CODE 0x59
#define AVC1394_VCR_CMD_TAPE_PLAYBACK_FORMAT 0xD3
#define AVC1394_VCR_CMD_TAPE_RECORDING_FORMAT 0xD2
#define AVC1394_VCR_CMD_TIME_CODE 0x51
#define AVC1394_VCR_CMD_TRANSPORT_STATE 0xD0
#define AVC1394_VCR_CMD_WIND 0xC4
#define AVC1394_VCR_CMD_WRITE_MIC 0x62

/* VCR subunit command operands */
#define AVC1394_VCR_OPERAND_LOAD_MEDIUM_EJECT 0x60
#define AVC1394_VCR_OPERAND_LOAD_MEDIUM_OPEN_TRAY 0x31
#define AVC1394_VCR_OPERAND_LOAD_MEDIUM_CLOSE_TRAY 0x32
#define AVC1394_VCR_OPERAND_PLAY_NEXT_FRAME 0x30
#define AVC1394_VCR_OPERAND_PLAY_SLOWEST_FORWARD 0x31
#define AVC1394_VCR_OPERAND_PLAY_SLOW_FORWARD_6 0x32
#define AVC1394_VCR_OPERAND_PLAY_SLOW_FORWARD_5 0x33
#define AVC1394_VCR_OPERAND_PLAY_SLOW_FORWARD_4 0x34
#define AVC1394_VCR_OPERAND_PLAY_SLOW_FORWARD_3 0x35
#define AVC1394_VCR_OPERAND_PLAY_SLOW_FORWARD_2 0x36
#define AVC1394_VCR_OPERAND_PLAY_SLOW_FORWARD_1 0x37
#define AVC1394_VCR_OPERAND_PLAY_X1_FORWARD     0x38
#define AVC1394_VCR_OPERAND_PLAY_FAST_FORWARD_1 0x39
#define AVC1394_VCR_OPERAND_PLAY_FAST_FORWARD_2 0x3A
#define AVC1394_VCR_OPERAND_PLAY_FAST_FORWARD_3 0x3B
#define AVC1394_VCR_OPERAND_PLAY_FAST_FORWARD_4 0x3C
#define AVC1394_VCR_OPERAND_PLAY_FAST_FORWARD_5 0x3D
#define AVC1394_VCR_OPERAND_PLAY_FAST_FORWARD_6 0x3E
#define AVC1394_VCR_OPERAND_PLAY_FASTEST_FORWARD 0x3F
#define AVC1394_VCR_OPERAND_PLAY_PREVIOUS_FRAME 0x40
#define AVC1394_VCR_OPERAND_PLAY_SLOWEST_REVERSE 0x41
#define AVC1394_VCR_OPERAND_PLAY_SLOW_REVERSE_6 0x42
#define AVC1394_VCR_OPERAND_PLAY_SLOW_REVERSE_5 0x43
#define AVC1394_VCR_OPERAND_PLAY_SLOW_REVERSE_4 0x44
#define AVC1394_VCR_OPERAND_PLAY_SLOW_REVERSE_3 0x45
#define AVC1394_VCR_OPERAND_PLAY_SLOW_REVERSE_2 0x46
#define AVC1394_VCR_OPERAND_PLAY_SLOW_REVERSE_1 0x47
#define AVC1394_VCR_OPERAND_PLAY_X1_REVERSE 0x48
#define AVC1394_VCR_OPERAND_PLAY_FAST_REVERSE_1 0x49
#define AVC1394_VCR_OPERAND_PLAY_FAST_REVERSE_2 0x4A
#define AVC1394_VCR_OPERAND_PLAY_FAST_REVERSE_3 0x4B
#define AVC1394_VCR_OPERAND_PLAY_FAST_REVERSE_4 0x4C
#define AVC1394_VCR_OPERAND_PLAY_FAST_REVERSE_5 0x4D
#define AVC1394_VCR_OPERAND_PLAY_FAST_REVERSE_6 0x4E
#define AVC1394_VCR_OPERAND_PLAY_FASTEST_REVERSE 0x4F
#define AVC1394_VCR_OPERAND_PLAY_REVERSE 0x65
#define AVC1394_VCR_OPERAND_PLAY_REVERSE_PAUSE 0x6D
#define AVC1394_VCR_OPERAND_PLAY_FORWARD 0x75
#define AVC1394_VCR_OPERAND_PLAY_FORWARD_PAUSE 0x7D

#define AVC1394_VCR_OPERAND_RECORD_UNSPEC_INSERTED 0x30
#define AVC1394_VCR_OPERAND_RECORD_AREA_23_INSERTED 0x31
#define AVC1394_VCR_OPERAND_RECORD_AREA_1_INSERTED 0x32
#define AVC1394_VCR_OPERAND_RECORD_AREA_123_INSERTED 0x33
#define AVC1394_VCR_OPERAND_RECORD_UNSPEC_INSERTED_PAUSE 0x40
#define AVC1394_VCR_OPERAND_RECORD_AREA_23_INSERTED_PAUSE 0x41
#define AVC1394_VCR_OPERAND_RECORD_AREA_1_INSERTED_PAUSE 0x42
#define AVC1394_VCR_OPERAND_RECORD_AREA_123_INSERTED_PAUSE 0x43
#define AVC1394_VCR_OPERAND_RECORD_RECORD 0x75
#define AVC1394_VCR_OPERAND_RECORD_PAUSE 0x7D

#define AVC1394_VCR_OPERAND_TRANSPORT_STATE 0x7F
#define AVC1394_VCR_OPERAND_WIND_HIGH_SPEED_REWIND 0x45
#define AVC1394_VCR_OPERAND_WIND_STOP 0x60
#define AVC1394_VCR_OPERAND_WIND_REWIND 0x65
#define AVC1394_VCR_OPERAND_WIND_FAST_FORWARD 0x75
#define AVC1394_VCR_OPERAND_TIME_CODE_CONTROL 0x20
#define AVC1394_VCR_OPERAND_TIME_CODE_STATUS 0x71
#define AVC1394_VCR_OPERAND_RELATIVE_TIME_COUNTER_CONTROL 0x20
#define AVC1394_VCR_OPERAND_RELATIVE_TIME_COUNTER_STATUS 0x71
#define AVC1394_VCR_OPERAND_TRANSPORT_STATE 0x7F
#define AVC1394_VCR_OPERAND_RECORDING_TIME_STATUS 0x71

/* recording speed */
#define AVC1394_VCR_OPERAND_RECORDING_SPEED_STANDARD 0x6F

#define AVC1394_VCR_OPERAND_MEDIUM_INFO_DVCR_STD 0x31
#define AVC1394_VCR_OPERAND_MEDIUM_INFO_DVCR_SMALL 0x32
#define AVC1394_VCR_OPERAND_MEDIUM_INFO_DVCR_MEDIUM 0x33
#define AVC1394_VCR_OPERAND_MEDIUM_INFO_VHS 0x22
#define AVC1394_VCR_OPERAND_MEDIUM_INFO_VHSC 0x23
#define AVC1394_VCR_OPERAND_MEDIUM_INFO_8MM 0x12
#define AVC1394_VCR_OPERAND_MEDIUM_INFO_MICROMV 0x41
#define AVC1394_VCR_OPERAND_MEDIUM_INFO_NONE 0x60
#define AVC1394_VCR_OPERAND_MEDIUM_INFO_UNKNOWN 0x7E

/* tape grade and write protect status */
#define AVC1394_VCR_OPERAND_MEDIUM_INFO_VHS_OK 0x30
#define AVC1394_VCR_OPERAND_MEDIUM_INFO_VHS_WP 0x31
#define AVC1394_VCR_OPERAND_MEDIUM_INFO_SVHS_OK 0x40
#define AVC1394_VCR_OPERAND_MEDIUM_INFO_SVHS_WP 0x41
#define AVC1394_VCR_OPERAND_MEDIUM_INFO_DVHS_OK 0x50
#define AVC1394_VCR_OPERAND_MEDIUM_INFO_DVHS_WP 0x51

#define AVC1394_VCR_RESPONSE_TRANSPORT_STATE_LOAD_MEDIUM 0x0000C100
#define AVC1394_VCR_RESPONSE_TRANSPORT_STATE_RECORD 0x0000C200
#define AVC1394_VCR_RESPONSE_TRANSPORT_STATE_PLAY 0x0000C300
#define AVC1394_VCR_RESPONSE_TRANSPORT_STATE_WIND 0x0000C400

/* Tuner subunit commands (Alphabetically) */
#define AVC1394_TUNER_COMMAND_DIRECT_SELECT_INFORMATION_TYPE 0xC8
#define AVC1394_TUNER_COMMAND_DIRECT_SELECT_DATA 0xCB
#define AVC1394_TUNER_COMMAND_CA_ENABLE 0xCC
#define AVC1394_TUNER_COMMAND_AVC1394_TUNER_STATUS 0xCD

/* Tuner subunit commands operands (Alphabetically) */
#define AVC1394_TUNER_COMMAND_DIRECT_SELECT_INFORMATION_TYPE 0xC8
#define AVC1394_TUNER_COMMAND_DIRECT_SELECT_DATA 0xCB
#define AVC1394_TUNER_COMMAND_CA_ENABLE 0xCC
#define AVC1394_TUNER_COMMAND_AVC1394_TUNER_STATUS 0xCD

enum avc1394_measurement_unit {
    AVC1394_VCR_MEASUREMENT_VIDEO_FRAME = 0,
    AVC1394_VCR_MEASUREMENT_VIDEO_SCENE,
    AVC1394_VCR_MEASUREMENT_VISS,
    AVC1394_VCR_MEASUREMENT_GOP,
    AVC1394_VCR_MEASUREMENT_INDEX,
    AVC1394_VCR_MEASUREMENT_SKIP,
    AVC1394_VCR_MEASUREMENT_PHOTO
};

#ifdef __cplusplus
extern "C" {
#endif

int
avc1394_send_command(raw1394handle_t handle, nodeid_t node, quadlet_t command);

int 
avc1394_send_command_block(raw1394handle_t handle, nodeid_t node,
	quadlet_t *command, int command_len);

quadlet_t 
avc1394_transaction(raw1394handle_t handle, nodeid_t node,
	quadlet_t quadlet, int retry);

quadlet_t *
avc1394_transaction_block(raw1394handle_t handle, nodeid_t node,
	quadlet_t *buf, int len, int retry);

int 
avc1394_open_descriptor(raw1394handle_t handle, nodeid_t node,
	quadlet_t ctype, quadlet_t subunit,
	unsigned char *descriptor_identifier, int len_descriptor_identifier,
	unsigned char readwrite);

int 
avc1394_close_descriptor(raw1394handle_t handle, nodeid_t node,
	quadlet_t ctype, quadlet_t subunit,
	unsigned char *descriptor_identifier, int len_descriptor_identifier);

int
avc1394_subunit_info(raw1394handle_t handle, nodeid_t node, quadlet_t *table);

/* supply one of the AVC1394_SUBUNIT_TYPE_... to see of node supports that 
   subunit type. Returns 1 for true, 0 for false. */
int
avc1394_check_subunit_type(raw1394handle_t handle, nodeid_t node, int subunit_type);

quadlet_t *
avc1394_unit_info(raw1394handle_t handle, nodeid_t node);


/************************ TARGET STUFF *****************************************/

/* your callback will receive this struct */
struct avc1394_command_response {
	byte_t status:4;
	byte_t reserved:4;
	byte_t subunit_id:3;
	byte_t subunit_type:5;
	byte_t opcode:8;
	byte_t operand[9];
};
typedef struct avc1394_command_response avc1394_cmd_rsp;

/* command callback prototype */
typedef int (*avc1394_command_handler_t)(struct avc1394_command_response*);

/* set the handler using this function */
int
avc1394_init_target( raw1394handle_t handle, avc1394_command_handler_t );

int
avc1394_close_target( raw1394handle_t handle );


#ifdef __cplusplus
}
#endif

#endif

