| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <iterator> | 6 #include <iterator> |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| (...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 } | 911 } |
| 912 | 912 |
| 913 void MimeUtil::RemoveProprietaryMediaTypesAndCodecsForTests() { | 913 void MimeUtil::RemoveProprietaryMediaTypesAndCodecsForTests() { |
| 914 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) { | 914 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) { |
| 915 non_image_map_.erase(proprietary_media_types[i]); | 915 non_image_map_.erase(proprietary_media_types[i]); |
| 916 media_map_.erase(proprietary_media_types[i]); | 916 media_map_.erase(proprietary_media_types[i]); |
| 917 } | 917 } |
| 918 allow_proprietary_codecs_ = false; | 918 allow_proprietary_codecs_ = false; |
| 919 } | 919 } |
| 920 | 920 |
| 921 // Returns true iff |profile_str| conforms to hex string "42y0", where y is one |
| 922 // of [8..F]. Requiring constraint_set0_flag be set and profile_idc be 0x42 is |
| 923 // taken from ISO-14496-10 7.3.2.1, 7.4.2.1, and Annex A.2.1. |
| 924 // |
| 925 // |profile_str| is the first four characters of the H.264 suffix string |
| 926 // (ignoring the last 2 characters of the full 6 character suffix that are |
| 927 // level_idc). From ISO-14496-10 7.3.2.1, it consists of: |
| 928 // 8 bits: profile_idc: required to be 0x42 here. |
| 929 // 1 bit: constraint_set0_flag : required to be true here. |
| 930 // 1 bit: constraint_set1_flag : ignored here. |
| 931 // 1 bit: constraint_set2_flag : ignored here. |
| 932 // 1 bit: constraint_set3_flag : ignored here. |
| 933 // 4 bits: reserved : required to be 0 here. |
| 934 // |
| 935 // The spec indicates other ways, not implemented here, that a |profile_str| |
| 936 // can indicate a baseline conforming decoder is sufficient for decode in Annex |
| 937 // A.2.1: "[profile_idc not necessarily 0x42] with constraint_set0_flag set and |
| 938 // in which level_idc and constraint_set3_flag represent a level less than or |
| 939 // equal to the specified level." |
| 940 static bool IsValidH264BaselineProfile(const std::string& profile_str) { |
| 941 uint32 constraint_set_bits; |
| 942 if (profile_str.size() != 4 || |
| 943 profile_str[0] != '4' || |
| 944 profile_str[1] != '2' || |
| 945 profile_str[3] != '0' || |
| 946 !base::HexStringToUInt(base::StringPiece(profile_str.c_str() + 2, 1), |
| 947 &constraint_set_bits)) { |
| 948 return false; |
| 949 } |
| 950 |
| 951 return constraint_set_bits >= 8; |
| 952 } |
| 953 |
| 921 static bool IsValidH264Level(const std::string& level_str) { | 954 static bool IsValidH264Level(const std::string& level_str) { |
| 922 uint32 level; | 955 uint32 level; |
| 923 if (level_str.size() != 2 || !base::HexStringToUInt(level_str, &level)) | 956 if (level_str.size() != 2 || !base::HexStringToUInt(level_str, &level)) |
| 924 return false; | 957 return false; |
| 925 | 958 |
| 926 // Valid levels taken from Table A-1 in ISO-14496-10. | 959 // Valid levels taken from Table A-1 in ISO-14496-10. |
| 927 // Essentially |level_str| is toHex(10 * level). | 960 // Essentially |level_str| is toHex(10 * level). |
| 928 return ((level >= 10 && level <= 13) || | 961 return ((level >= 10 && level <= 13) || |
| 929 (level >= 20 && level <= 22) || | 962 (level >= 20 && level <= 22) || |
| 930 (level >= 30 && level <= 32) || | 963 (level >= 30 && level <= 32) || |
| 931 (level >= 40 && level <= 42) || | 964 (level >= 40 && level <= 42) || |
| 932 (level >= 50 && level <= 51)); | 965 (level >= 50 && level <= 51)); |
| 933 } | 966 } |
| 934 | 967 |
| 935 // Handle parsing H.264 codec IDs as outlined in RFC 6381 | 968 // Handle parsing H.264 codec IDs as outlined in RFC 6381 and ISO-14496-10. |
| 936 // avc1.42E0xx - H.264 Baseline | 969 // avc1.42y0xx, y >= 8 - H.264 Baseline |
| 937 // avc1.4D40xx - H.264 Main | 970 // avc1.4D40xx - H.264 Main |
| 938 // avc1.6400xx - H.264 High | 971 // avc1.6400xx - H.264 High |
| 939 // | 972 // |
| 940 // avc1.xxxxxx & avc3.xxxxxx are considered ambiguous forms that | 973 // avc1.xxxxxx & avc3.xxxxxx are considered ambiguous forms that are trying to |
| 941 // are trying to signal H.264 Baseline. | 974 // signal H.264 Baseline. For example, the idc_level, profile_idc and |
| 975 // constraint_set3_flag pieces may explicitly require decoder to conform to |
| 976 // baseline profile at the specified level (see Annex A and constraint_set0 in |
| 977 // ISO-14496-10). |
| 942 static bool ParseH264CodecID(const std::string& codec_id, | 978 static bool ParseH264CodecID(const std::string& codec_id, |
| 943 MimeUtil::Codec* codec, | 979 MimeUtil::Codec* codec, |
| 944 bool* is_ambiguous) { | 980 bool* is_ambiguous) { |
| 945 // Make sure we have avc1.xxxxxx or avc3.xxxxxx | 981 // Make sure we have avc1.xxxxxx or avc3.xxxxxx |
| 946 if (codec_id.size() != 11 || | 982 if (codec_id.size() != 11 || |
| 947 (!StartsWithASCII(codec_id, "avc1.", true) && | 983 (!StartsWithASCII(codec_id, "avc1.", true) && |
| 948 !StartsWithASCII(codec_id, "avc3.", true))) { | 984 !StartsWithASCII(codec_id, "avc3.", true))) { |
| 949 return false; | 985 return false; |
| 950 } | 986 } |
| 951 | 987 |
| 952 std::string profile = StringToUpperASCII(codec_id.substr(5, 4)); | 988 std::string profile = StringToUpperASCII(codec_id.substr(5, 4)); |
| 953 if (profile == "42E0") { | 989 if (IsValidH264BaselineProfile(profile)) { |
| 954 *codec = MimeUtil::H264_BASELINE; | 990 *codec = MimeUtil::H264_BASELINE; |
| 955 } else if (profile == "4D40") { | 991 } else if (profile == "4D40") { |
| 956 *codec = MimeUtil::H264_MAIN; | 992 *codec = MimeUtil::H264_MAIN; |
| 957 } else if (profile == "6400") { | 993 } else if (profile == "6400") { |
| 958 *codec = MimeUtil::H264_HIGH; | 994 *codec = MimeUtil::H264_HIGH; |
| 959 } else { | 995 } else { |
| 960 *codec = MimeUtil::H264_BASELINE; | 996 *codec = MimeUtil::H264_BASELINE; |
| 961 *is_ambiguous = true; | 997 *is_ambiguous = true; |
| 962 return true; | 998 return true; |
| 963 } | 999 } |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1356 post_data->append("\r\n" + value + "\r\n"); | 1392 post_data->append("\r\n" + value + "\r\n"); |
| 1357 } | 1393 } |
| 1358 | 1394 |
| 1359 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, | 1395 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, |
| 1360 std::string* post_data) { | 1396 std::string* post_data) { |
| 1361 DCHECK(post_data); | 1397 DCHECK(post_data); |
| 1362 post_data->append("--" + mime_boundary + "--\r\n"); | 1398 post_data->append("--" + mime_boundary + "--\r\n"); |
| 1363 } | 1399 } |
| 1364 | 1400 |
| 1365 } // namespace net | 1401 } // namespace net |
| OLD | NEW |