root/trunk/freebob/src/avmidiinfoblock.cpp

Revision 22, 2.5 kB (checked in by pieterpalmers, 19 years ago)

- Added the following info block handlers:

Basic read functionallity only.

- Changed Makefile.am to reflect these new files
- Removed a bug from avdescriptor->readBuffer
- Added some basic tests of the new handlers (remark: the new tests could be device specific)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /* avmidiinfoblock.cpp
2  * Copyright (C) 2004 by Pieter Palmers
3  *
4  * This file is part of FreeBob.
5  *
6  * FreeBob is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * FreeBob is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with FreeBob; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18  * MA 02111-1307 USA.
19  */
20
21
22 #include <string.h>
23 #include <errno.h>
24 #include <libavc1394/avc1394.h>
25 #include <libavc1394/avc1394_vcr.h>
26 #include "debugmodule.h"
27
28 #include "avdescriptor.h"
29 #include "avinfoblock.h"
30 #include "avnameinfoblock.h"
31 #include "avmidiinfoblock.h"
32
33 AvMidiInfoBlock::AvMidiInfoBlock(AvDescriptor *parent, int address) : AvInfoBlock(parent,address) {
34         // do some more valid checks
35         if (getType() != 0x8104) {
36                 bValid=false;
37         }
38        
39         unsigned int nb_streams=readByte(6);
40         unsigned int position=0;
41         AvNameInfoBlock *tmpNameBlock;
42        
43         if (nb_streams>0) {
44                 position=address+7;
45                 for (unsigned int i=0;i<nb_streams;i++) {
46                        
47                         tmpNameBlock=new AvNameInfoBlock(parent, position);
48                        
49                         if (tmpNameBlock && (tmpNameBlock->isValid())) {
50                                 position+=tmpNameBlock->getLength()+2; // the 2 is due to the fact that the length of the length field of the infoblock isn't accounted for;
51                                
52                                 // add to child list
53                                 cNameInfoBlocks.push_back(tmpNameBlock);
54                         } else {
55                                 debugPrint(DEBUG_LEVEL_INFO,"Invalid name block in Midi info Block...\n");
56                                 bValid=false;
57                                 break; // what to do now?
58                         }
59                 }
60                
61         }
62        
63         // no optional info blocks please...
64        
65 }
66
67 AvMidiInfoBlock::~AvMidiInfoBlock() {
68        
69         vector<AvNameInfoBlock *>::iterator it;
70         for( it = cNameInfoBlocks.begin(); it != cNameInfoBlocks.end(); it++ ) {
71                 delete *it;
72         }
73
74 }
75
76 unsigned int AvMidiInfoBlock::getNbStreams() {
77         if(isValid()) {
78                 return readByte(6);
79         } else {
80                 return 0;
81         }
82 }
83
84 unsigned char *AvMidiInfoBlock::getName(unsigned int streamIdx) {
85         AvNameInfoBlock *tmpNameBlock;
86        
87         if ((streamIdx<getNbStreams()) && (streamIdx<cNameInfoBlocks.size())) {
88                 tmpNameBlock =cNameInfoBlocks.at(streamIdx);
89                 if (tmpNameBlock) {
90                         return tmpNameBlock->getName();
91                 } else {
92                         return NULL;
93                 }
94         }
95         return NULL;
96 }
Note: See TracBrowser for help on using the browser.