]> git.sesse.net Git - mlt/blob - src/modules/decklink/common.cpp
83f5e531b099fb103e8dc724a42975d56ef67028
[mlt] / src / modules / decklink / common.cpp
1 /*
2  * common.cpp -- Blackmagic Design DeckLink common functions
3  * Copyright (C) 2012 Dan Dennedy <dan@dennedy.org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library 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 GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with consumer library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #include "common.h"
21 #include <stdlib.h>
22
23 #ifdef __DARWIN__
24
25 char* getCString( DLString aDLString )
26 {
27         char* CString = (char*) malloc( 64 );
28         CFStringGetCString( aDLString, CString, 64, kCFStringEncodingMacRoman );
29         return CString;
30 }
31
32 void freeCString( char* aCString )
33 {
34         if ( aCString ) free( aCString );
35 }
36
37 void freeDLString( DLString aDLString )
38 {
39         if ( aDLString ) CFRelease( aDLString );
40 }
41
42 #elif defined(WIN32)
43
44 char* getCString( DLString aDLString )
45 {
46         char* CString = NULL;
47         if ( aDLString )
48         {
49                 int size = WideCharToMultiByte( CP_UTF8, 0, aDLString, -1, NULL, 0, NULL, NULL );
50                 if (size)
51                 {
52                         CString = new char[ size ];
53                         size = WideCharToMultiByte( CP_UTF8, 0, aDLString, -1, CString, size, NULL, NULL );
54                         if ( !size )
55                         {
56                                 delete[] CString;
57                                 CString = NULL;
58                         }
59                 }
60         }
61         return CString;
62 }
63
64 void freeCString( char* aCString )
65 {
66         delete[] aCString;
67 }
68
69 void freeDLString( DLString aDLString )
70 {
71         if ( aDLString ) free( (void*) aDLString );
72 }
73
74 #else
75
76 char* getCString( DLString aDLString )
77 {
78         return aDLString? (char*) aDLString : NULL;
79 }
80
81 void freeCString( char* aCString )
82 {
83 }
84
85 void freeDLString( DLString aDLString )
86 {
87         if ( aDLString ) free( (void*) aDLString );
88 }
89
90 #endif
91