1986 TInt j = 0; |
1980 TInt j = 0; |
1987 for (i=0; i<headerLength; i++) |
1981 for (i=0; i<headerLength; i++) |
1988 { |
1982 { |
1989 if ( inputPtr[i] == 0 && |
1983 if ( inputPtr[i] == 0 && |
1990 inputPtr[i+1] == 0 && |
1984 inputPtr[i+1] == 0 && |
1991 inputPtr[i+2] == 0 && |
1985 inputPtr[i+2] == 1 ) |
1992 inputPtr[i+3] == 1 ) |
1986 { // found bytestream header [(00) 00 00 01] |
1993 { // found bytestream header [00 00 00 01] |
|
1994 PRINT((_L("CCamC3GPDataSinkImp::ConvertAVCHeaderByteStreamL found header at: %d"), i)); |
1987 PRINT((_L("CCamC3GPDataSinkImp::ConvertAVCHeaderByteStreamL found header at: %d"), i)); |
1995 nalType = inputPtr[i+4] & 0x1F; |
1988 nalType = inputPtr[i+3] & 0x1F; |
1996 PRINT((_L("CCamC3GPDataSinkImp::ConvertAVCHeaderByteStreamL NAL type: %d"), nalType)); |
1989 PRINT((_L("CCamC3GPDataSinkImp::ConvertAVCHeaderByteStreamL NAL type: %d"), nalType)); |
1997 if(nalType == 7) // SPS |
1990 if(nalType == 7) // SPS |
1998 { |
1991 { |
1999 numSPS++; |
1992 numSPS++; |
2000 // find length of SPS |
1993 // find length of SPS |
2001 TInt j; |
1994 TInt j; |
2002 for (j=4; i+j+3<headerLength; j++) |
1995 for (j=3; i+j+3<headerLength; j++) |
2003 { |
1996 { |
2004 if ( inputPtr[i+j] == 0 && |
1997 if ( inputPtr[i+j] == 0 && |
2005 inputPtr[i+j+1] == 0 && |
1998 inputPtr[i+j+1] == 0 && |
2006 inputPtr[i+j+2] == 0 && |
1999 inputPtr[i+j+2] == 1 ) |
2007 inputPtr[i+j+3] == 1 ) |
|
2008 { |
2000 { |
2009 totalSPSLength = j-i-4; |
2001 totalSPSLength = j-i-3; |
2010 PRINT((_L("CCamC3GPDataSinkImp::ConvertAVCHeaderByteStreamL SPS length: %d, count: %d"), totalSPSLength, numSPS)); |
2002 PRINT((_L("CCamC3GPDataSinkImp::ConvertAVCHeaderByteStreamL SPS length: %d, count: %d"), totalSPSLength, numSPS)); |
2011 break; |
2003 break; |
2012 } |
2004 } |
2013 } |
2005 } |
2014 // if we didn't find next bytestream header then this is last buffer |
2006 // if we didn't find next bytestream header then this is last buffer |
2015 if ( totalSPSLength == 0 ) |
2007 if ( totalSPSLength == 0 ) |
2016 { |
2008 { |
2017 totalSPSLength = headerLength - i - 4; |
2009 totalSPSLength = headerLength - i - 3; |
2018 PRINT((_L("CCamC3GPDataSinkImp::ConvertAVCHeaderByteStreamL SPS length: %d (last), count: %d"), totalSPSLength, numSPS)); |
2010 PRINT((_L("CCamC3GPDataSinkImp::ConvertAVCHeaderByteStreamL SPS length: %d (last), count: %d"), totalSPSLength, numSPS)); |
2019 } |
2011 } |
2020 |
2012 |
2021 // First store the SPS unit length with two bytes |
2013 // First store the SPS unit length with two bytes |
2022 spsPtr[0] = (totalSPSLength >> 8) & 0xFF; |
2014 spsPtr[0] = (totalSPSLength >> 8) & 0xFF; |
2023 spsPtr[1] = totalSPSLength & 0xFF; |
2015 spsPtr[1] = totalSPSLength & 0xFF; |
2024 |
2016 |
2025 // Copy the SPS unit to the buffer |
2017 // Copy the SPS unit to the buffer |
2026 Mem::Copy(&spsPtr[2], &inputPtr[i+4] , totalSPSLength); |
2018 Mem::Copy(&spsPtr[2], &inputPtr[i+3] , totalSPSLength); |
2027 totalSPSLength +=2; |
2019 totalSPSLength +=2; |
2028 } |
2020 } |
2029 else if ( nalType == 8 ) // PPS) |
2021 else if ( nalType == 8 ) // PPS) |
2030 { |
2022 { |
2031 numPPS++; |
2023 numPPS++; |
2032 // find length of PPS |
2024 // find length of PPS |
2033 for (j=4; i+j+3<headerLength; j++) |
2025 for (j=3; i+j+3<headerLength; j++) |
2034 { |
2026 { |
2035 if ( inputPtr[i+j] == 0 && |
2027 if ( inputPtr[i+j] == 0 && |
2036 inputPtr[i+j+1] == 0 && |
2028 inputPtr[i+j+1] == 0 && |
2037 inputPtr[i+j+2] == 0 && |
2029 inputPtr[i+j+2] == 1 ) |
2038 inputPtr[i+j+3] == 1 ) |
|
2039 { |
2030 { |
2040 totalPPSLength = j-i-4; |
2031 totalPPSLength = j-i-3; |
2041 PRINT((_L("CCamC3GPDataSinkImp::ConvertAVCHeaderByteStreamL PPS length: %d, count: %d"), totalPPSLength, numPPS)); |
2032 PRINT((_L("CCamC3GPDataSinkImp::ConvertAVCHeaderByteStreamL PPS length: %d, count: %d"), totalPPSLength, numPPS)); |
2042 break; |
2033 break; |
2043 } |
2034 } |
2044 } |
2035 } |
2045 // if we didn't find next bytestream header then this is last buffer |
2036 // if we didn't find next bytestream header then this is last buffer |
2046 if ( totalPPSLength == 0 ) |
2037 if ( totalPPSLength == 0 ) |
2047 { |
2038 { |
2048 totalPPSLength = headerLength - i - 4; |
2039 totalPPSLength = headerLength - i - 3; |
2049 PRINT((_L("CCamC3GPDataSinkImp::ConvertAVCHeaderByteStreamL PPS length: %d (last), count: %d"), totalPPSLength, numPPS)); |
2040 PRINT((_L("CCamC3GPDataSinkImp::ConvertAVCHeaderByteStreamL PPS length: %d (last), count: %d"), totalPPSLength, numPPS)); |
2050 } |
2041 } |
2051 |
2042 |
2052 // First store the SPS unit length with two bytes |
2043 // First store the SPS unit length with two bytes |
2053 ppsPtr[0] = (totalPPSLength >> 8) & 0xFF; |
2044 ppsPtr[0] = (totalPPSLength >> 8) & 0xFF; |
2054 ppsPtr[1] = totalPPSLength & 0xFF; |
2045 ppsPtr[1] = totalPPSLength & 0xFF; |
2055 |
2046 |
2056 // Copy the SPS unit to the buffer |
2047 // Copy the SPS unit to the buffer |
2057 Mem::Copy(&ppsPtr[2], &inputPtr[i+4], totalPPSLength); |
2048 Mem::Copy(&ppsPtr[2], &inputPtr[i+3], totalPPSLength); |
2058 totalPPSLength +=2; |
2049 totalPPSLength +=2; |
2059 } |
2050 } |
2060 } |
2051 } |
2061 } |
2052 } |
2062 |
2053 |
2135 TUint8* inputPtr = (TUint8*)(aBuffer->Data().Ptr()); |
2126 TUint8* inputPtr = (TUint8*)(aBuffer->Data().Ptr()); |
2136 TUint headerLength = aBuffer->Data().Length(); |
2127 TUint headerLength = aBuffer->Data().Length(); |
2137 PRINT((_L("CCamC3GPDataSinkImp::ConvertBytestreamHeadersToNALSizesL buffer length: %d"), headerLength)); |
2128 PRINT((_L("CCamC3GPDataSinkImp::ConvertBytestreamHeadersToNALSizesL buffer length: %d"), headerLength)); |
2138 |
2129 |
2139 TInt nalLength = 0; |
2130 TInt nalLength = 0; |
|
2131 TInt outputOffset = 0; |
2140 TBool moreThanOneNAL = EFalse; |
2132 TBool moreThanOneNAL = EFalse; |
2141 TInt i = 0; |
2133 TInt i = 0; |
2142 TInt j = 0; |
2134 TInt j = 0; |
2143 for (i=0; i<headerLength; i++) |
2135 for (i=0; i<headerLength-2; i++) |
2144 { |
2136 { |
2145 if ( inputPtr[i] == 0 && |
2137 if ( inputPtr[i] == 0 && |
2146 inputPtr[i+1] == 0 && |
2138 inputPtr[i+1] == 0 && |
2147 inputPtr[i+2] == 0 && |
2139 inputPtr[i+2] == 1 ) |
2148 inputPtr[i+3] == 1 ) |
2140 { // found bytestream header [(00) 00 00 01] |
2149 { // found bytestream header [00 00 00 01] |
|
2150 PRINT((_L("CCamC3GPDataSinkImp::ConvertBytestreamHeadersToNALSizesL found header at: %d"), i)); |
2141 PRINT((_L("CCamC3GPDataSinkImp::ConvertBytestreamHeadersToNALSizesL found header at: %d"), i)); |
2151 PRINT((_L("CCamC3GPDataSinkImp::ConvertBytestreamHeadersToNALSizesL NAL type: %d"), TInt(inputPtr[i+4] & 0x1F) )); |
2142 PRINT((_L("CCamC3GPDataSinkImp::ConvertBytestreamHeadersToNALSizesL NAL type: %d"), TInt(inputPtr[i+3] & 0x1F) )); |
2152 if (moreThanOneNAL) |
2143 if (moreThanOneNAL) |
2153 {// we found start of next NAL unit in memory buffer so update previous size |
2144 {// we found start of next NAL unit in memory buffer so update previous size |
2154 nalLength = i-j-4; // 4 is the bytestream header |
2145 nalLength = i-j-3; // 3 is the bytestream header |
2155 PRINT((_L("CCamC3GPDataSinkImp::ConvertBytestreamHeadersToNALSizesL NAL length: %d"), nalLength)); |
2146 PRINT((_L("CCamC3GPDataSinkImp::ConvertBytestreamHeadersToNALSizesL NAL length: %d, toPos: %d"), nalLength, outputOffset)); |
2156 inputPtr[j] = TUint8((nalLength >> 24) & 0xff); |
2147 iVideoBuffer[outputOffset] = TUint8((nalLength >> 24) & 0xff); |
2157 inputPtr[j+1] = TUint8((nalLength >> 16) & 0xff); |
2148 iVideoBuffer[outputOffset+1] = TUint8((nalLength >> 16) & 0xff); |
2158 inputPtr[j+2] = TUint8((nalLength >> 8) & 0xff); |
2149 iVideoBuffer[outputOffset+2] = TUint8((nalLength >> 8) & 0xff); |
2159 inputPtr[j+3] = TUint8(nalLength & 0xff); |
2150 iVideoBuffer[outputOffset+3] = TUint8(nalLength & 0xff); |
|
2151 PRINT((_L("CCamC3GPDataSinkImp::ConvertBytestreamHeadersToNALSizesL copy to:%d, from:%d, amount:%d"), outputOffset+4, j+3, nalLength )); |
|
2152 Mem::Copy(iVideoBuffer+outputOffset+4, inputPtr+j+3, nalLength); |
|
2153 outputOffset += 4 + nalLength; // 4 bytes for length information. |
2160 } |
2154 } |
2161 moreThanOneNAL = ETrue; |
2155 moreThanOneNAL = ETrue; |
2162 j=i; |
2156 j=i; |
2163 } |
2157 } |
2164 } |
2158 } |
2165 // and update last (or if only 1 NAL size: |
2159 // and update last (or if only 1 NAL size: |
2166 nalLength = headerLength-j-4; // 4 is the bytestream header |
2160 nalLength = headerLength-j-3; // 3 is the bytestream header |
2167 PRINT((_L("CCamC3GPDataSinkImp::ConvertBytestreamHeadersToNALSizesL last NAL length: %d"), nalLength)); |
2161 PRINT((_L("CCamC3GPDataSinkImp::ConvertBytestreamHeadersToNALSizesL last NAL length: %d, toPos: %d"), nalLength, outputOffset)); |
2168 inputPtr[j] = TUint8((nalLength >> 24) & 0xff); |
2162 iVideoBuffer[outputOffset] = TUint8((nalLength >> 24) & 0xff); |
2169 inputPtr[j+1] = TUint8((nalLength >> 16) & 0xff); |
2163 iVideoBuffer[outputOffset+1] = TUint8((nalLength >> 16) & 0xff); |
2170 inputPtr[j+2] = TUint8((nalLength >> 8) & 0xff); |
2164 iVideoBuffer[outputOffset+2] = TUint8((nalLength >> 8) & 0xff); |
2171 inputPtr[j+3] = TUint8(nalLength & 0xff); |
2165 iVideoBuffer[outputOffset+3] = TUint8(nalLength & 0xff); |
|
2166 PRINT((_L("CCamC3GPDataSinkImp::ConvertBytestreamHeadersToNALSizesL copy to:%d, from:%d, amount:%d"), outputOffset+4, j+3, nalLength )); |
|
2167 Mem::Copy(iVideoBuffer+outputOffset+4, inputPtr+j+3, nalLength); |
|
2168 |
|
2169 outputOffset += 4 + nalLength; // 4 bytes for length information. |
|
2170 iVideoBufferFrameSize = outputOffset; |
2172 PRINT((_L("CCamC3GPDataSinkImp::ConvertBytestreamHeadersToNALSizesL out"))); |
2171 PRINT((_L("CCamC3GPDataSinkImp::ConvertBytestreamHeadersToNALSizesL out"))); |
2173 } |
2172 } |
2174 |
2173 |
2175 // ----------------------------------------------------------------------------- |
2174 // ----------------------------------------------------------------------------- |
2176 // CCamC3GPDataSinkImp::ConvertNALEncapsulationToNALSizes |
2175 // CCamC3GPDataSinkImp::ConvertNALEncapsulationToNALSizes |