Skip to content
Snippets Groups Projects
Commit 12ce35af authored by Emil Ivov's avatar Emil Ivov
Browse files

Moves format matching from AsbtractMediaStream into MediaFormat and MediaFormatImpl

parent f9242755
No related branches found
No related tags found
No related merge requests found
......@@ -173,8 +173,7 @@ private MediaFormat createMediaFormat(
* clockRate. We just want to make sure that the channels and the
* format parameters match.
*/
if (AbstractMediaStream.matches(
format,
if (format.matches(
format.getMediaType(),
format.getEncoding(), format.getClockRate(), channels,
fmtps))
......
......@@ -608,4 +608,87 @@ public String toString()
return str.toString();
}
/**
* Determines whether this <tt>MediaFormat</tt> matches properties of a
* specific <tt>MediaFormat</tt>, such as <tt>mediaType</tt>,
* <tt>encoding</tt>, <tt>clockRate</tt> and <tt>channels</tt> for
* <tt>MediaFormat</tt>s with <tt>mediaType</tt> equal to
* {@link MediaType#AUDIO}.
*
* @param format the {@link MediaFormat} whose properties we'd like to
* examine and compare with ours.
*/
public boolean matches(MediaFormat format)
{
if(format == null)
return false;
MediaType mediaType = format.getMediaType();
String encoding = format.getEncoding();
double clockRate = format.getClockRate();
int channels = MediaType.AUDIO.equals(mediaType)
? ((AudioMediaFormat) format).getChannels()
: MediaFormatFactory.CHANNELS_NOT_SPECIFIED;
Map<String, String> formatParameters = format.getFormatParameters();
return matches(
mediaType, encoding, clockRate, channels, formatParameters);
}
/**
* Determines whether this <tt>MediaFormat</tt> has specific values
* for its properties <tt>mediaType</tt>, <tt>encoding</tt>,
* <tt>clockRate</tt> and <tt>channels</tt> for <tt>MediaFormat</tt>s with
* <tt>mediaType</tt> equal to {@link MediaType#AUDIO}.
*
* @param mediaType the type we expect {@link MediaFormat} to have
* @param encoding the encoding we are looking for.
* @param clockRate the clock rate that we'd like the format to have.
* @param channels the number of channels that expect to find in this format
* @param formatParameters the format parameters expected to match these of
* the specified <tt>format</tt>
* @return <tt>true</tt> if the specified <tt>format</tt> has specific
* values for its properties <tt>mediaType</tt>, <tt>encoding</tt>,
* <tt>clockRate</tt> and <tt>channels</tt>; otherwise, <tt>false</tt>
*/
public boolean matches(MediaType mediaType,
String encoding,
double clockRate,
int channels,
Map<String, String> formatParameters)
{
// mediaType
// encoding
if (!getMediaType().equals(mediaType)
|| !getEncoding().equals(encoding))
return false;
// clockRate
if (clockRate != MediaFormatFactory.CLOCK_RATE_NOT_SPECIFIED)
{
double formatClockRate = getClockRate();
if ((formatClockRate != MediaFormatFactory.CLOCK_RATE_NOT_SPECIFIED)
&& (formatClockRate != clockRate))
return false;
}
// channels
if (MediaType.AUDIO.equals(mediaType))
{
if (channels == MediaFormatFactory.CHANNELS_NOT_SPECIFIED)
channels = 1;
int formatChannels = ((AudioMediaFormat) this).getChannels();
if (formatChannels == MediaFormatFactory.CHANNELS_NOT_SPECIFIED)
formatChannels = 1;
if (formatChannels != channels)
return false;
}
// formatParameters
return formatParametersMatch(formatParameters);
}
}
......@@ -83,64 +83,6 @@ public String getName()
return name;
}
/**
* Determines whether a specific <tt>MediaFormat</tt> has specific values
* for its properties <tt>mediaType</tt>, <tt>encoding</tt>,
* <tt>clockRate</tt> and <tt>channels</tt> for <tt>MediaFormat</tt>s with
* <tt>mediaType</tt> equal to {@link MediaType#AUDIO}.
*
* @param format the {@link MediaFormat} whose properties we'd like to
* examine
* @param mediaType the type we expect {@link MediaFormat} to have
* @param encoding the encoding we are looking for.
* @param clockRate the clock rate that we'd like the format to have.
* @param channels the number of channels that expect to find in this format
* @param formatParameters the format parameters expected to match these of
* the specified <tt>format</tt>
* @return <tt>true</tt> if the specified <tt>format</tt> has specific
* values for its properties <tt>mediaType</tt>, <tt>encoding</tt>,
* <tt>clockRate</tt> and <tt>channels</tt>; otherwise, <tt>false</tt>
*/
public static boolean matches(
MediaFormat format,
MediaType mediaType,
String encoding, double clockRate, int channels,
Map<String, String> formatParameters)
{
// mediaType
// encoding
if (!format.getMediaType().equals(mediaType)
|| !format.getEncoding().equals(encoding))
return false;
// clockRate
if (clockRate != MediaFormatFactory.CLOCK_RATE_NOT_SPECIFIED)
{
double formatClockRate = format.getClockRate();
if ((formatClockRate != MediaFormatFactory.CLOCK_RATE_NOT_SPECIFIED)
&& (formatClockRate != clockRate))
return false;
}
// channels
if (MediaType.AUDIO.equals(mediaType))
{
if (channels == MediaFormatFactory.CHANNELS_NOT_SPECIFIED)
channels = 1;
int formatChannels = ((AudioMediaFormat) format).getChannels();
if (formatChannels == MediaFormatFactory.CHANNELS_NOT_SPECIFIED)
formatChannels = 1;
if (formatChannels != channels)
return false;
}
// formatParameters
return format.formatParametersMatch(formatParameters);
}
/**
* Removes the specified <tt>PropertyChangeListener</tt> from this stream so
* that it won't receive further property change events.
......
......@@ -171,4 +171,47 @@ public interface MediaFormat
*/
@Override
public String toString();
/**
* Determines whether this <tt>MediaFormat</tt> matches properties of a
* specific <tt>MediaFormat</tt>, such as <tt>mediaType</tt>,
* <tt>encoding</tt>, <tt>clockRate</tt> and <tt>channels</tt> for
* <tt>MediaFormat</tt>s with <tt>mediaType</tt> equal to
* {@link MediaType#AUDIO}.
*
* @param format the {@link MediaFormat} whose properties we'd like to
* examine
* @param mediaType the type we expect {@link MediaFormat} to have
* @param encoding the encoding we are looking for.
* @param clockRate the clock rate that we'd like the format to have.
* @param channels the number of channels that expect to find in this format
* @param formatParameters the format parameters expected to match these of
* the specified <tt>format</tt>
* @return <tt>true</tt> if the specified <tt>format</tt> has specific
* values for its properties <tt>mediaType</tt>, <tt>encoding</tt>,
* <tt>clockRate</tt> and <tt>channels</tt>; otherwise, <tt>false</tt>
*/
public boolean matches(MediaFormat format);
/**
* Determines whether this <tt>MediaFormat</tt> has specific values
* for its properties <tt>mediaType</tt>, <tt>encoding</tt>,
* <tt>clockRate</tt> and <tt>channels</tt> for <tt>MediaFormat</tt>s with
* <tt>mediaType</tt> equal to {@link MediaType#AUDIO}.
*
* @param mediaType the type we expect {@link MediaFormat} to have
* @param encoding the encoding we are looking for.
* @param clockRate the clock rate that we'd like the format to have.
* @param channels the number of channels that expect to find in this format
* @param formatParameters the format parameters expected to match these of
* the specified <tt>format</tt>
* @return <tt>true</tt> if the specified <tt>format</tt> has specific
* values for its properties <tt>mediaType</tt>, <tt>encoding</tt>,
* <tt>clockRate</tt> and <tt>channels</tt>; otherwise, <tt>false</tt>
*/
public boolean matches(MediaType mediaType,
String encoding,
double clockRate,
int channels,
Map<String, String> formatParameters);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment