wxSoundStream& wxSoundStreamG72X::Read(void *buffer, wxUint32 len) { wxUint16 *old_linear; register wxUint16 *linear_buffer; register wxUint32 real_len; register wxUint32 countdown = len; real_len = (len * 8 / m_n_bits); old_linear = linear_buffer = new wxUint16[real_len]; m_router->Read(linear_buffer, real_len); real_len = (wxUint32)(m_router->GetLastAccess() * ((float)m_n_bits / 8)); if (!real_len) return *m_router; m_io_buffer = (wxUint8 *)buffer; m_current_b_pos = 0; while (countdown != 0) { PutBits(m_coder(*linear_buffer++, AUDIO_ENCODING_LINEAR, m_state)); countdown--; } m_lastcount = real_len; m_snderror = m_router->GetError(); delete[] old_linear; return *this; }
static int writeData(void* _call) { WriterAVCallData_t* call = (WriterAVCallData_t*) _call; unsigned char PesHeader[PES_MAX_HEADER_SIZE]; unsigned char FakeHeaders[64]; // 64bytes should be enough to make the fake headers unsigned int FakeHeaderLength; unsigned int ExtraLength = 0; unsigned char Version = 5; unsigned int FakeStartCode = (Version << 8) | PES_VERSION_FAKE_START_CODE; unsigned int HeaderLength = 0; unsigned int usecPerFrame = 41708; /* Hellmaster1024: default value */ BitPacker_t ld = {FakeHeaders, 0, 32}; divx_printf(10, "\n"); if (call == NULL) { divx_err("call data is NULL...\n"); return 0; } divx_printf(10, "AudioPts %lld\n", call->Pts); if ((call->data == NULL) || (call->len <= 0)) { divx_err("parsing NULL Data. ignoring...\n"); return 0; } if (call->fd < 0) { divx_err("file pointer < 0. ignoring ...\n"); return 0; } usecPerFrame = 1000000000 / call->FrameRate; divx_printf(10, "Microsecends per frame = %d\n", usecPerFrame); memset(FakeHeaders, 0, sizeof(FakeHeaders)); /* Create info record for frame parser */ /* divx4 & 5 VOS PutBits(&ld, 0x0, 8); PutBits(&ld, 0x0, 8); */ PutBits(&ld, 0x1b0, 32); // startcode PutBits(&ld, 0, 8); // profile = reserved PutBits(&ld, 0x1b2, 32); // startcode (user data) PutBits(&ld, 0x53545443, 32); // STTC - an embedded ST timecode from an avi file PutBits(&ld, usecPerFrame , 32); // microseconds per frame FlushBits(&ld); FakeHeaderLength = (ld.Ptr - (FakeHeaders)); if (initialHeader) ExtraLength = call->private_size; HeaderLength = InsertPesHeader (PesHeader, call->len, MPEG_VIDEO_PES_START_CODE, call->Pts, FakeStartCode); int iovcnt = 0; struct iovec iov[4]; iov[iovcnt].iov_base = PesHeader; iov[iovcnt].iov_len = HeaderLength; iovcnt++; iov[iovcnt].iov_base = FakeHeaders; iov[iovcnt].iov_len = FakeHeaderLength; iovcnt++; if (initialHeader) { initialHeader = 0; iov[iovcnt].iov_base = call->private_data; iov[iovcnt].iov_len = call->private_size; iovcnt++; } iov[iovcnt].iov_base = call->data; iov[iovcnt].iov_len = call->len; iovcnt++; int len = writev(call->fd, iov, iovcnt); divx_printf(10, "xvid_Write < len=%d\n", len); return len; }