Skip to content
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

Refactor the constructors of pointer wrappers #2373

Closed
wants to merge 1 commit into from

Commits on May 11, 2022

  1. Refactor the constructors of pointer wrappers (pytorch#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: pytorch#2373
    
    Reviewed By: hwangjeff
    
    Differential Revision: D36230148
    
    Pulled By: mthrok
    
    fbshipit-source-id: 289426662c12d42ff9c7d956c58b8cef7e6c9221
    mthrok authored and facebook-github-bot committed May 11, 2022
    Configuration menu
    Copy the full SHA
    ab32da9 View commit details
    Browse the repository at this point in the history