ASDCP::Result_t ASDCP::Wav::SimpleWaveHeader::WriteToFile(Kumu::FileWriter& OutFile) const { ui32_t write_count; byte_t tmp_header[SimpleWavHeaderLength]; byte_t* p = tmp_header; static ui32_t fmt_len = sizeof(format) + sizeof(nchannels) + sizeof(samplespersec) + sizeof(avgbps) + sizeof(blockalign) + sizeof(bitspersample) + sizeof(cbsize); ui32_t RIFF_len = data_len + SimpleWavHeaderLength - 8; memcpy(p, &FCC_RIFF, sizeof(fourcc)); p += 4; *((ui32_t*)p) = KM_i32_LE(RIFF_len); p += 4; memcpy(p, &FCC_WAVE, sizeof(fourcc)); p += 4; memcpy(p, &FCC_fmt_, sizeof(fourcc)); p += 4; *((ui32_t*)p) = KM_i32_LE(fmt_len); p += 4; *((ui16_t*)p) = KM_i16_LE(format); p += 2; *((ui16_t*)p) = KM_i16_LE(nchannels); p += 2; *((ui32_t*)p) = KM_i32_LE(samplespersec); p += 4; *((ui32_t*)p) = KM_i32_LE(avgbps); p += 4; *((ui16_t*)p) = KM_i16_LE(blockalign); p += 2; *((ui16_t*)p) = KM_i16_LE(bitspersample); p += 2; *((ui16_t*)p) = KM_i16_LE(cbsize); p += 2; memcpy(p, &FCC_data, sizeof(fourcc)); p += 4; *((ui32_t*)p) = KM_i32_LE(data_len); p += 4; return OutFile.Write(tmp_header, SimpleWavHeaderLength, &write_count); }
Result_t AS_02::MXF::AS02IndexWriterVBR::WriteToFile(Kumu::FileWriter& Writer) { assert(m_Dict); ASDCP::FrameBuffer index_body_buffer; ui32_t index_body_size = m_PacketList->m_List.size() * MaxIndexSegmentSize; // segment-count * max-segment-size Result_t result = index_body_buffer.Capacity(index_body_size); ui64_t start_position = 0; if ( m_CurrentSegment != 0 ) { m_CurrentSegment->IndexDuration = m_CurrentSegment->IndexEntryArray.size(); start_position = m_CurrentSegment->IndexStartPosition + m_CurrentSegment->IndexDuration; m_CurrentSegment = 0; } std::list<InterchangeObject*>::iterator pl_i = m_PacketList->m_List.begin(); for ( ; pl_i != m_PacketList->m_List.end() && KM_SUCCESS(result); pl_i++ ) { InterchangeObject* object = *pl_i; object->m_Lookup = m_Lookup; ASDCP::FrameBuffer WriteWrapper; WriteWrapper.SetData(index_body_buffer.Data() + index_body_buffer.Size(), index_body_buffer.Capacity() - index_body_buffer.Size()); result = object->WriteToBuffer(WriteWrapper); index_body_buffer.Size(index_body_buffer.Size() + WriteWrapper.Size()); delete *pl_i; *pl_i = 0; } m_PacketList->m_List.clear(); if ( KM_SUCCESS(result) ) { IndexByteCount = index_body_buffer.Size(); UL body_ul(m_Dict->ul(MDD_ClosedCompleteBodyPartition)); result = Partition::WriteToFile(Writer, body_ul); } if ( KM_SUCCESS(result) ) { ui32_t write_count = 0; result = Writer.Write(index_body_buffer.RoData(), index_body_buffer.Size(), &write_count); assert(write_count == index_body_buffer.Size()); } if ( KM_SUCCESS(result) ) { m_CurrentSegment = new IndexTableSegment(m_Dict); assert(m_CurrentSegment); AddChildObject(m_CurrentSegment); m_CurrentSegment->DeltaEntryArray.push_back(IndexTableSegment::DeltaEntry()); m_CurrentSegment->IndexEditRate = m_EditRate; m_CurrentSegment->IndexStartPosition = start_position; } return result; }
ASDCP::Result_t ASDCP::KLVFilePacket::WriteKLToFile(Kumu::FileWriter& Writer, const UL& label, ui32_t length) { byte_t buffer[kl_length]; memcpy(buffer, label.Value(), label.Size()); if ( ! Kumu::write_BER(buffer+SMPTE_UL_LENGTH, length, MXF_BER_LENGTH) ) return RESULT_FAIL; ui32_t write_count; Writer.Write(buffer, kl_length, &write_count); assert(write_count == kl_length); return RESULT_OK; }
Result_t AS_02::MXF::AS02IndexWriterCBR::WriteToFile(Kumu::FileWriter& Writer) { assert(m_Dict); ASDCP::FrameBuffer index_body_buffer; ui32_t index_body_size = MaxIndexSegmentSize; // segment-count * max-segment-size Result_t result = index_body_buffer.Capacity(index_body_size); m_CurrentSegment = new IndexTableSegment(m_Dict); assert(m_CurrentSegment); m_CurrentSegment->m_Lookup = m_Lookup; m_CurrentSegment->IndexEditRate = m_EditRate; m_CurrentSegment->IndexStartPosition = 0; m_CurrentSegment->IndexDuration = m_Duration; m_CurrentSegment->EditUnitByteCount = m_SampleSize; AddChildObject(m_CurrentSegment); ASDCP::FrameBuffer WriteWrapper; WriteWrapper.SetData(index_body_buffer.Data() + index_body_buffer.Size(), index_body_buffer.Capacity() - index_body_buffer.Size()); result = m_CurrentSegment->WriteToBuffer(WriteWrapper); index_body_buffer.Size(index_body_buffer.Size() + WriteWrapper.Size()); delete m_CurrentSegment; m_CurrentSegment = 0; m_PacketList->m_List.clear(); if ( KM_SUCCESS(result) ) { IndexByteCount = index_body_buffer.Size(); UL body_ul(m_Dict->ul(MDD_ClosedCompleteBodyPartition)); result = Partition::WriteToFile(Writer, body_ul); } if ( KM_SUCCESS(result) ) { ui32_t write_count = 0; result = Writer.Write(index_body_buffer.RoData(), index_body_buffer.Size(), &write_count); assert(write_count == index_body_buffer.Size()); } return result; }
ASDCP::Result_t ASDCP::RF64::SimpleRF64Header::WriteToFile(Kumu::FileWriter& OutFile) const { static ui32_t fmt_len = sizeof(format) + sizeof(nchannels) + sizeof(samplespersec) + sizeof(avgbps) + sizeof(blockalign) + sizeof(bitspersample) + sizeof(cbsize); ui32_t write_count = 0; ui64_t RIFF_len = data_len + SimpleWavHeaderLength - 8; // DefaultLogSink().Debug("RIFF_len is %llu.\n", RIFF_len); byte_t* tmp_header = NULL; ui32_t header_len = 0; if (RIFF_len > MAX_RIFF_LEN) { DefaultLogSink().Debug("Will write out an RF64 wave file.\n"); ui32_t data32_len = ((data_len < MAX_RIFF_LEN) ? data_len : MAX_RIFF_LEN); ui64_t data64_len = ((data_len < MAX_RIFF_LEN) ? 0 : data_len); static ui32_t ds64_len = sizeof(RIFF_len) + sizeof(data64_len) + sizeof(SAMPLE_COUNT) + sizeof(TABLE_LEN); header_len = SIMPLE_RF64_HEADER_LEN; tmp_header = new byte_t[header_len]; byte_t* p = tmp_header; memcpy(p, &FCC_RF64, sizeof(fourcc)); p += 4; *((ui32_t*)p) = KM_i32_LE(MAX_RIFF_LEN); p += 4; memcpy(p, &Wav::FCC_WAVE, sizeof(fourcc)); p += 4; memcpy(p, &FCC_ds64, sizeof(fourcc)); p += 4; *((ui32_t*)p) = KM_i32_LE(ds64_len); p += 4; *((ui64_t*)p) = KM_i64_LE(RIFF_len); p += 8; *((ui64_t*)p) = KM_i64_LE(data64_len); p += 8; *((ui64_t*)p) = KM_i64_LE(SAMPLE_COUNT); p += 8; *((ui32_t*)p) = KM_i32_LE(TABLE_LEN); p += 4; memcpy(p, &Wav::FCC_fmt_, sizeof(fourcc)); p += 4; *((ui32_t*)p) = KM_i32_LE(fmt_len); p += 4; *((ui16_t*)p) = KM_i16_LE(format); p += 2; *((ui16_t*)p) = KM_i16_LE(nchannels); p += 2; *((ui32_t*)p) = KM_i32_LE(samplespersec); p += 4; *((ui32_t*)p) = KM_i32_LE(avgbps); p += 4; *((ui16_t*)p) = KM_i16_LE(blockalign); p += 2; *((ui16_t*)p) = KM_i16_LE(bitspersample); p += 2; *((ui16_t*)p) = KM_i16_LE(cbsize); p += 2; memcpy(p, &Wav::FCC_data, sizeof(fourcc)); p += 4; *((ui32_t*)p) = KM_i32_LE(data32_len); p += 4; write_count = (p - tmp_header); } else { DefaultLogSink().Debug("Will write out a regular wave file.\n"); header_len = SimpleWavHeaderLength; tmp_header = new byte_t[header_len]; byte_t* p = tmp_header; memcpy(p, &Wav::FCC_RIFF, sizeof(fourcc)); p += 4; *((ui32_t*)p) = KM_i32_LE(RIFF_len); p += 4; memcpy(p, &Wav::FCC_WAVE, sizeof(fourcc)); p += 4; memcpy(p, &Wav::FCC_fmt_, sizeof(fourcc)); p += 4; *((ui32_t*)p) = KM_i32_LE(fmt_len); p += 4; *((ui16_t*)p) = KM_i16_LE(format); p += 2; *((ui16_t*)p) = KM_i16_LE(nchannels); p += 2; *((ui32_t*)p) = KM_i32_LE(samplespersec); p += 4; *((ui32_t*)p) = KM_i32_LE(avgbps); p += 4; *((ui16_t*)p) = KM_i16_LE(blockalign); p += 2; *((ui16_t*)p) = KM_i16_LE(bitspersample); p += 2; *((ui16_t*)p) = KM_i16_LE(cbsize); p += 2; memcpy(p, &Wav::FCC_data, sizeof(fourcc)); p += 4; *((ui32_t*)p) = KM_i32_LE(data_len); p += 4; write_count = (p - tmp_header); } if (header_len != write_count) { DefaultLogSink().Warn("Expected to write %u bytes but wrote %u bytes for header.\n", header_len, write_count); } write_count = 0; ASDCP::Result_t r = OutFile.Write(tmp_header, header_len, &write_count); delete [] tmp_header; return r; }