Skip to content

Prepare sdt loader for ffmpeg #522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from Jul 20, 2018
Merged

Prepare sdt loader for ffmpeg #522

merged 1 commit into from Jul 20, 2018

Conversation

ghost
Copy link

@ghost ghost commented Jun 21, 2018

Extracted from #420.


/// Load the structure of the archive
/// Omit the extension in filename
bool load(const std::string& filename);
bool load(const rwfs::path& path);

/// Load a file from the archive to memory and pass a pointer to it
/// Warning: Please delete[] the memory in the end.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to remove

@ghost
Copy link
Author

ghost commented Jun 22, 2018

@madebr has suggested on IRC to prevent linking FFmpeg to rwlib. I'll try something like this: sdt loader provides raw data and SoundManager deals with it.

@ghost
Copy link
Author

ghost commented Jun 23, 2018

Updated, please review. ;)
(adding extra comment, because not sure if forced push will trigger message)

#endif

// Expose audio metadata
channels = codecContext->channels;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: using size_t for int. WaveHeader uses uint16_t while AVCodecContext uses int..

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you think about casting or changing some variable's type?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of casting. Tho, as uint16_t is being used in WaveHeader is size_t really needed.

@@ -65,7 +43,7 @@ bool LoaderSDT::findAssetInfo(size_t index, LoaderSDTFile& out) {
return false;
}

char* LoaderSDT::loadToMemory(size_t index, bool asWave) {
std::unique_ptr<char[]> LoaderSDT::loadToMemory(size_t index, bool asWave) {
LoaderSDTFile assetInfo;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assetInfo is also declared in header so is this intentional?


WaveHeader* header = reinterpret_cast<WaveHeader*>(raw_data);
WaveHeader* header = reinterpret_cast<WaveHeader*>(raw_data.get());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use auto

@ghost
Copy link
Author

ghost commented Jul 4, 2018

Done. ;)

auto ioBuffer = static_cast<uint8_t*>(av_malloc(ioBufferSize));

/// Convert memory, in order to match required layout for ffmpeg
memcpy(input.ptr, raw_sound.get(), input.size);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this need to be copied? Can't the memory for raw_sound be given to the input?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like pointer casting, but memory layout should match. I'll check.

/// Alocate memory for buffer
/// Memory freeded at the end
static constexpr size_t ioBufferSize = 4096;
auto ioBuffer = static_cast<uint8_t*>(av_malloc(ioBufferSize));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use unique_ptr with a custom deleter to handle specific dealloc functions from C APIs.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'll be confusing for reading.

Also, actually buffer is deleted before context, this change will flip order. FFmpeg really likes to change api, so I think it's better to be as close as possible to "template" use.

if (avformat_open_input(&formatContext, "nothint", nullptr, nullptr) != 0) {
av_frame_free(&frame);
RW_ERROR("Error opening audio file (" << index << ")");
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should formatContext->pb be freed in these early branches?

Copy link
Author

@ghost ghost Jul 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be, I mean it needs rebase.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Function loadSound returns
AVFormatContext with custom AVIOContext.
@danhedron
Copy link
Member

LGTM

@danhedron danhedron merged commit 2f8ae7f into rwengine:master Jul 20, 2018
@ghost ghost deleted the prepare_sdt_loader_for_ffmpeg branch July 21, 2018 19:43
@ghost ghost mentioned this pull request Aug 11, 2018
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants