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