Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/mincequi/scream
Browse files Browse the repository at this point in the history
  • Loading branch information
mincequi committed May 13, 2020
2 parents dc41070 + c257d6b commit 1df0776
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Scream/Scream.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<Configuration>Win8.1 Debug</Configuration>
<Platform Condition="'$(Platform)' == ''">Win32</Platform>
<RootNamespace>Scream</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8.1 Debug|Win32'" Label="Configuration">
Expand Down
20 changes: 9 additions & 11 deletions Scream/ac3encoder.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#include "stdafx.h"
#include "ac3encoder.h"

#include <mfapi.h>
#include <mferror.h>

#pragma comment(lib, "mfplat.lib")
#pragma comment(lib, "mfuuid.lib")

template<class T>
void SafeRelease(T **ppT)
{
Expand Down Expand Up @@ -60,6 +64,10 @@ HRESULT Ac3Encoder::Initialize(UINT32 sampleRate, UINT32 numChannels)
hr = CoCreateInstance(clsids[0], NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&m_transform));
}

if (!SUCCEEDED(hr)) {
return hr;
}

// Create and set output type
MFCreateMediaType(&m_outputType);
m_outputType->SetGUID(MF_MT_MAJOR_TYPE, outInfo.guidMajorType);
Expand Down Expand Up @@ -103,7 +111,7 @@ IMFSample* Ac3Encoder::Process(void *inBuffer, UINT32 inSize)
// transform back in accepting state.
if (outSample) {
while (auto sample = ProcessOutput()) {
ReleaseSample(sample);
sample->Release();
}
}

Expand Down Expand Up @@ -147,16 +155,6 @@ void Ac3Encoder::ProcessInput(void *inSamples, UINT32 inSize)
pBuffer->Release();
}

void Ac3Encoder::ReleaseSample(IMFSample *sample)
{
IMFMediaBuffer* buffer = nullptr;
sample->GetBufferByIndex(0, &buffer);

sample->Release();
// No idea why, but we have to release the buffer twice.
while (buffer->Release()) {};
}

void Ac3Encoder::Drain()
{
m_transform->ProcessMessage(MFT_MESSAGE_COMMAND_DRAIN, 0);
Expand Down
1 change: 0 additions & 1 deletion Scream/ac3encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class Ac3Encoder
void SetBitrate(UINT32 kbps);

IMFSample* Process(void *inSamples, UINT32 inSize);
void ReleaseSample(IMFSample *sample);

void Drain();

Expand Down
7 changes: 4 additions & 3 deletions TestSender/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ void MainWindow::on_sendIntervalSlider_valueChanged(int value)
void MainWindow::onTimeout()
{
static uint32_t i = 0;
std::array<int16_t, 1536*2-16> samples;
std::array<int16_t, 1536*2> samples;
for (size_t j = 0; j < samples.size(); j += 2) {
samples[j] = 16384*sin(m_testFrequency * 2 * M_PI * ++i / m_samplerate);
samples[j+1] = samples[j];
}

if (auto sample = m_encoder.Process(samples.data(), samples.size()*2)) {
if (auto sample = m_encoder.Process(samples.data(), samples.size()*sizeof(int16_t))) {
s_rtpheader.seq = _byteswap_ushort(s_seq);
s_rtpheader.ts = _byteswap_ulong(s_ts);

Expand All @@ -92,7 +92,8 @@ void MainWindow::onTimeout()
rtpPacket.append(char(1));
rtpPacket.append((const char*)ac3Data, currentAc3Length);
buffer->Unlock();
m_encoder.ReleaseSample(sample);
buffer->Release();
sample->Release();

m_socket.writeDatagram(rtpPacket, QHostAddress("239.255.77.77"), 4010);

Expand Down

0 comments on commit 1df0776

Please sign in to comment.