Example #1
0
        /// <summary>
        /// COM entry point for IMediaObject.SetOutputType
        /// </summary>
        /// <remarks>
        /// There should be no need to modify or override this method.  It will call the
        /// abstract and virtual methods to perform its work.
        /// </remarks>
        public int SetOutputType(int ulStreamIndex, AMMediaType pmt, DMOSetType dwFlags)
        {
            int hr = S_OK;

            try
            {
                // Avoid multi-threaded access issues
                lock(this)
                {
                    m_Log.Write(string.Format("SetOutputType({0}, {1})", ulStreamIndex, dwFlags));

                    // Validate the stream number
                    if (ulStreamIndex >= m_NumOutputs || ulStreamIndex < 0)
                    {
                        return DMOResults.E_InvalidStreamIndex;
                    }

                    // Validate the flags
                    if ( (dwFlags & ~ (DMOSetType.Clear | DMOSetType.TestOnly)) > 0)
                    {
                        return E_INVALIDARG;
                    }

                    // If they requested to clear the current type
                    if ( (dwFlags & DMOSetType.Clear) > 0)
                    {
                        DsUtils.FreeAMMediaType(m_OutputInfo[ulStreamIndex].CurrentMediaType);
                        m_OutputInfo[ulStreamIndex].fTypeSet = false;

                        // Re-check to see if all the non-optional streams still have types
                        if (!CheckAllTypesSet())
                        {
                            // We aren't in a runnable state anymore, flush things
                            Flush();
                            FreeStreamingResources();
                        }
                        hr = S_OK;
                    }
                    else
                    {
                        if (null != pmt)
                        {
                            m_Log.WriteNoTS(string.Format(" requested out: {0}", DsToString.AMMediaTypeToString(pmt)));

                            //  Check if the type is already set
                            if (!OutputTypeSet(ulStreamIndex))
                            {
                                // Check to see if we support the requested format
                                hr = InternalCheckOutputType(ulStreamIndex, pmt);
                                if (hr >= 0)
                                {
                                    hr = S_OK;

                                    // If we weren't just being tested, actually set the type
                                    if ( (dwFlags & DMOSetType.TestOnly) == 0)
                                    {
                                        // Free any previous mediatype
                                        if (OutputTypeSet(ulStreamIndex))
                                        {
                                            DsUtils.FreeAMMediaType(m_OutputInfo[ulStreamIndex].CurrentMediaType);
                                        }
                                        m_OutputInfo[ulStreamIndex].CurrentMediaType = MoCloneMediaType(pmt);
                                        m_OutputInfo[ulStreamIndex].fTypeSet = true;

                                        // Re-check to see if all the non-optional streams still have types
                                        CheckAllTypesSet();
                                    }
                                }
                            }
                            else
                            {
                                // Type is set, so reject any type that's not identical
                                if (!TypesMatch(pmt, OutputType(ulStreamIndex)))
                                {
                                    hr = DMOResults.E_InvalidType;
                                }
                                else
                                {
                                    hr = S_OK;
                                }
                            }
                        }
                        else
                        {
                            hr = E_POINTER;
                        }
                    }

                    m_Log.WriteNoTS(string.Format(":{0}\r\n", hr));
                }
            }
            catch (Exception e)
            {
                // Generic handling of all exceptions.  While .NET will turn exceptions into
                // HRESULTS "automatically", I prefer to have some place I can set a breakpoint.
                hr = CatFail(e);
            }

            return hr;
        }
Example #2
0
    /// <summary>
    /// COM entry point for IMediaObject.SetOutputType
    /// </summary>
    /// <param name="streamIndex">Zero-based index of an input stream on the DMO.</param>
    /// <param name="pmt">Pointer to a <see cref="AMMediaType"/> structure that 
    /// specifies the media type.</param>
    /// <param name="flags">Bitwise combination of zero or more flags 
    /// from the DMO_SET_TYPE_FLAGS enumeration.</param>
    /// <returns>A HRESULT value.</returns>
    /// <remarks>
    /// There should be no need to modify or override this method.  It will call the
    /// abstract and virtual methods to perform its work.
    /// </remarks>
    public int SetOutputType(int streamIndex, AMMediaType pmt, DMOSetType flags)
    {
      int hr = SOK;

      try
      {
        // Avoid multi-threaded access issues
        lock (this)
        {
          // Validate the stream number
          if (streamIndex >= this.numOutputs || streamIndex < 0)
          {
            return DMOResults.E_InvalidStreamIndex;
          }

          // Validate the flags
          if ((flags & ~(DMOSetType.Clear | DMOSetType.TestOnly)) > 0)
          {
            return EINVALIDARG;
          }

          // If they requested to clear the current type
          if ((flags & DMOSetType.Clear) > 0)
          {
            DsUtils.FreeAMMediaType(this.outputInfo[streamIndex].CurrentMediaType);
            this.outputInfo[streamIndex].TypeSet = false;

            // Re-check to see if all the non-optional streams still have types
            if (!this.CheckAllTypesSet())
            {
              // We aren't in a runnable state anymore, flush things
              this.Flush();
              this.FreeStreamingResources();
            }

            hr = SOK;
          }
          else
          {
            if (null != pmt)
            {
              // Check if the type is already set
              if (!this.OutputTypeSet(streamIndex))
              {
                // Check to see if we support the requested format
                hr = this.InternalCheckOutputType(streamIndex, pmt);
                if (hr >= 0)
                {
                  hr = SOK;

                  // If we weren't just being tested, actually set the type
                  if ((flags & DMOSetType.TestOnly) == 0)
                  {
                    // Free any previous mediatype
                    if (this.OutputTypeSet(streamIndex))
                    {
                      DsUtils.FreeAMMediaType(this.outputInfo[streamIndex].CurrentMediaType);
                    }

                    this.outputInfo[streamIndex].CurrentMediaType = MoCloneMediaType(pmt);
                    this.outputInfo[streamIndex].TypeSet = true;

                    // Re-check to see if all the non-optional streams still have types
                    this.CheckAllTypesSet();
                  }
                }
              }
              else
              {
                // Type is set, so reject any type that's not identical
                if (!TypesMatch(pmt, this.OutputType(streamIndex)))
                {
                  hr = DMOResults.E_InvalidType;
                }
                else
                {
                  hr = SOK;
                }
              }
            }
            else
            {
              hr = EPOINTER;
            }
          }
        }
      }
      catch (Exception e)
      {
        // Generic handling of all exceptions.  While .NET will turn exceptions into
        // HRESULTS "automatically", I prefer to have some place I can set a breakpoint.
        hr = this.CatFail(e);
      }

      return hr;
    }