Refactor the constructors of pointer wrappers (#2373)
Summary:
This commit refactor the constructor of wrapper classes so that
wrapper classes are only responsible for deallocation of underlying
FFmpeg custom structures.
The responsibility of custom initialization is moved to helper functions.
Context:
FFmpeg API uses bunch of raw pointers, which require dedicated allocater
and deallcoator. In torchaudio we wrap these pointers with
`std::unique_ptr<>` to adopt RAII semantics.
Currently all of the customization logics required for `Streamer` are
handled by the constructor of wrapper class. Like the following;
```
AVFormatContextPtr(
const std::string& src,
const std::string& device,
const std::map<std::string, std::string>& option);
```
This constructor allocates the raw `AVFormatContext*` pointer,
while initializing it with the given option, then it parses the
input media.
As we consider the write/encode features, which require different way
of initializing the `AVFormatContext*`, making it the responsibility
of constructors of `AVFormatContextPtr` reduce the flexibility.
Thus this commit moves the customization to helper factory function.
- `AVFormatContextPtr(...)` -> `get_input_format_context(...)`
- `AVCodecContextPtr(...)` -> `get_decode_context(...)`
Pull Request resolved: https://github.com/pytorch/audio/pull/2373
Reviewed By: hwangjeff
Differential Revision: D36230148
Pulled By: mthrok
fbshipit-source-id: 202d57d549223904ee958193f3b386ef5a9cda3a
Showing
Please register or sign in to comment