[go: nahoru, domu]

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

MediaFoundationReader: a couple HE-AAC & HE-AACv2 cases #223

Closed
tfwio opened this issue Aug 8, 2017 · 2 comments
Closed

MediaFoundationReader: a couple HE-AAC & HE-AACv2 cases #223

tfwio opened this issue Aug 8, 2017 · 2 comments

Comments

@tfwio
Copy link
tfwio commented Aug 8, 2017

Greetz!

HE-AAC/HE-AACv2 cause an exception.
the (quick) fix below also causes an exception if we have an aac_lc mono file ;( in which case i suppose a try/catch can revert on SetCurrentMediaType if one were inclined.

[edit: wow i sure edited the h out of this -- no more edits;]

see:

after calling var currentMediaType = GetCurrentMediaType(reader);
if subType == AAC && numchannels == 1, doubling numchannels and sample-rate appears to get the format(s) working.

I'd tested various HE-AAC/AACv2 files at different channel and samplerate settings am aware of and it seems to do the trick.

    /// <summary>
    /// Creates the reader (overridable by )
    /// </summary>
    protected virtual IMFSourceReader CreateReader(MediaFoundationReaderSettings settings)
    {
      IMFSourceReader reader;
      MediaFoundationInterop.MFCreateSourceReaderFromURL(file, null, out reader);
      reader.SetStreamSelection(MediaFoundationInterop.MF_SOURCE_READER_ALL_STREAMS, false);
      reader.SetStreamSelection(MediaFoundationInterop.MF_SOURCE_READER_FIRST_AUDIO_STREAM, true);

      // Create a partial media type indicating that we want uncompressed PCM audio

      var partialMediaType = new MediaType();
      partialMediaType.MajorType = MediaTypes.MFMediaType_Audio;
      partialMediaType.SubType = settings.RequestFloatOutput ? AudioSubtypes.MFAudioFormat_Float : AudioSubtypes.MFAudioFormat_PCM;

      var currentMediaType = GetCurrentMediaType(reader);

      // HE-AAC (and v2) seems to halve the samplerate
      if (currentMediaType.SubType==AudioSubtypes.MFAudioFormat_AAC && currentMediaType.ChannelCount==1)
      {
        currentMediaType.SampleRate *= 2;
        currentMediaType.ChannelCount *= 2;
      }
      // mono, low sample rate files can go wrong on Windows 10 unless we specify here
      partialMediaType.ChannelCount = currentMediaType.ChannelCount;
      partialMediaType.SampleRate = currentMediaType.SampleRate;
      

      // set the media type
      // can return MF_E_INVALIDMEDIATYPE if not supported
      reader.SetCurrentMediaType(MediaFoundationInterop.MF_SOURCE_READER_FIRST_AUDIO_STREAM, IntPtr.Zero, partialMediaType.MediaFoundationObject);

      Marshal.ReleaseComObject(currentMediaType.MediaFoundationObject);
      return reader;
    }

Many thanks :)

@markheath
Copy link
Contributor

thanks for reporting. feel free to issue a PR with these changes.

@Ahmed-Abdelhameed
Copy link
Contributor
Ahmed-Abdelhameed commented Sep 3, 2017

I encountered a similar issue #231. Just tested your fix, and it worked with MP4 files with HE-AAC audio format. Kindly issue a PR so we can have this committed ASAP. Thank you!

@markheath looks like the OP has been off for a couple weeks. Can you please commit this change? I'm happy with the NuGet package, and don't want to modify & rebuild the library for this little change.

I would really appreciate that.
Thank you!

ArclightSA added a commit to ArclightSA/NAudio that referenced this issue Sep 19, 2017
* AudioFileReader supports filenames ending with .aif, resolves naudio#216

* v1.8.2 release

* Added "Data" property

Added "Data" property to allow for non Unicode decoding of text.

* Fixed typos

* With Directsound, when another playback is started after the playback has completely stopped, the problem of mixing noise is solved.

* Based on the advice of markheath, clearing processing of the secondary buffer is converted into a helper method.

* PropVariant fields now public

Changed field access modifiers from private to public to allow creation of custom variants for settings MMDevice instances property values.

* Addition of missing IPropertyStore methods for PropertyStore class.

Added SetValue and Commit methods to allow one to write new property values for MMDevice instance.

* Addition of new PropertyKeys class members

Declaration of new static PropertyKey fields:
- PKEY_Device_DeviceDesc, description property
- PKEY_Device_ControllerDeviceId, contains device id of controller device for given endpoint
- PKEY_Device_InterafaceKey, contains interface key path
for PropertyKeys static class.

* StorageAccessMode enum now public

* Blob struct now public

* Modified GetPropertyInformation for public use

Method GetPropertyInformation now public. Access flag can now be changed when accessing property store for given MMDevice.

* Fixed description

* Added XML documentation for new public members

* improved support for mono AAC, fixes naudio#223

* Improved support for mono AAC

Multiplying the SampleRate & ChannelCount will cause exception with aac_lc mono _(it's only required with HE-AAC)_.

* Fix different behavior between Win7 and Win10.

* fix NullReferenceException opening AsioOut by index. resolves naudio#234

* v1.8.3 release

* Prevent audio files from staying locked

Fixing an issue that caused audio files used by the MediaFoundationReader class to stay locked after the class instance is disposed, due to unreleased COM object.

* additional constructor for MultiplexingWaveProvider
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

No branches or pull requests

3 participants