houxiao
2017-08-09 d9ffa50c7e8d6b8c3157690aef8e2a70af1d1695
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
#include "MediaHelper.h"
//#include <libbase64.h>
#include <liveMedia/liveMedia.hh>
#include <liveMedia/Base64.hh>
 
uint8_t* base64_decode(char const* in, size_t inSize, size_t& resultSize, bool trimTrailingZeros)
{
    unsigned _resultSize = resultSize;
    Boolean _trimTrailingZeros = trimTrailingZeros;
    unsigned char* ret = base64Decode(in, inSize, _resultSize, _trimTrailingZeros);
    resultSize = _resultSize;
    return ret;
}
 
char* base64_encode(char const* orig, size_t origLength)
{
    unsigned _origLength = origLength;
    return base64Encode(orig, _origLength);
}
 
SPropRecord* parseSPropParameterSets(char const* sPropParameterSetsStr, int& numSPropRecords)
{  
  // Make a copy of the input string, so we can replace the commas with '\0's:  
  char* inStr = strDup(sPropParameterSetsStr);  
  if (inStr == NULL)
  {  
    numSPropRecords = 0;  
    return NULL;  
  }  
  
  // Count the number of commas (and thus the number of parameter sets):  
  numSPropRecords = 1;  
  char* s;  
  for (s = inStr; *s != '\0'; ++s)
  {  
    if (*s == ',')
    {  
      ++numSPropRecords;  
      *s = '\0';  
    }  
  }  
  
  // Allocate and fill in the result array:  
  SPropRecord* resultArray = new SPropRecord[numSPropRecords];
  s = inStr;  
  for (unsigned i = 0; i < numSPropRecords; ++i)
  {  
    resultArray[i].sPropBytes = nullptr;
    resultArray[i].sPropLength = 0;
    
    unsigned sPropLength = 0;
 
    uint8_t* tmp = base64Decode(s, sPropLength, True);
    if (tmp != nullptr && sPropLength > 0)
    {
        resultArray[i].sPropBytes = new uint8_t[256];
        memcpy(resultArray[i].sPropBytes, tmp, sPropLength);
    }
    delete[] tmp;
    
    //base64_decode(s, strlen(s), (char*)resultArray[i].sPropBytes, &sPropLength, 0);
    resultArray[i].sPropLength = sPropLength;
    
    s += strlen(s) + 1;  
  }  
  
  delete[] inStr;
  return resultArray;
}